home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / pty4 / part02 < prev    next >
Encoding:
Text File  |  1992-02-18  |  66.2 KB  |  3,187 lines

  1. Newsgroups: comp.sources.unix
  2. From: brnstnd@nyu.edu (Dan Bernstein)
  3. Subject: v25i128: Generalized interface to pseudo-tty devices, Part02/09
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: brnstnd@nyu.edu (Dan Bernstein)
  8. Posting-Number: Volume 25, Issue 128
  9. Archive-Name: pty4/part02
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 2 (of 9)."
  18. # Contents:  COPYRIGHT FILES FORMLETTER biff.1 condom.1 disconnect.1
  19. #   disconnect.c getoptquiet.c lock.c ptyerr.c ptylogs.c ptymisc.c
  20. #   ptytty.h reconnect.1 reconnect.c script.1 sess.1 sessconnlog.c
  21. #   sesskill.1 sesskill.c sesslog.c sesswhere.1 sesswhere.c sesswho.1
  22. #   sesswho.c sigdfl.3 tplay.c trecord.1 trecord.c tscript.1
  23. #   ttydetach.c ttydfl.7 username.c users.c wall.c who.1 write.1
  24. # Wrapped by vixie@cognition.pa.dec.com on Wed Feb 19 13:35:02 1992
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  28. else
  29. echo shar: Extracting \"'COPYRIGHT'\" \(2170 characters\)
  30. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  31. pty version 4.0, February 9, 1992.
  32. Copyright (c) 1992, Daniel J. Bernstein.
  33. All rights reserved.
  34. X
  35. I want this program to be distributed freely in original form.
  36. X
  37. Once you've received a legal copy of this program, you can use it.
  38. XForever. Nobody can take that right away from you. You can make changes
  39. and backup copies for your use (or, if you're an organization, for the
  40. use of everyone in the organization). You can distribute patches (though
  41. not patched versions). You'd have all these rights even if I didn't tell
  42. you about them.
  43. X
  44. Copyright law gives an author the exclusive right to copy and distribute his
  45. works. So that you don't have to worry about these legalities, I grant you the
  46. right to make and distribute exact and complete copies of this program.
  47. X
  48. On the other hand, I don't want this program sold without my permission.
  49. Unless I give you permission, you may not charge for copies. You may charge for
  50. distribution---but only if you first warn the recipient that the code is free,
  51. and tell him where you got it from.
  52. X
  53. I don't want this program distributed without my name on it. I also don't
  54. want lots of different versions running around, so unless I give you permission
  55. you can't send out a modified version. It's perfectly all right to send other
  56. people a description of how to make your changes (i.e., a patch), because then
  57. each recipient knows firsthand what patches he's installed, and I won't go
  58. chasing ghosts. (An author has no right to control patches in any case.)
  59. X
  60. If you run an archive site: When you receive a patch supposedly from me, do you
  61. apply it to the original package and repackage it? I encourage you to change
  62. your policy, if for no other reason than to give recipients a fallback in case
  63. of buggy patches. If you're really set on this, how about including the patches
  64. as separate, unapplied PATCHnn files inside the package? That's fine by me.
  65. X
  66. If you have questions about this program or about this notice, or if you
  67. would like additional rights beyond those granted above, or if you have
  68. a patch that you don't mind sharing, please contact me on the Internet
  69. at brnstnd@nyu.edu. Special arrangements are available for vendors.
  70. END_OF_FILE
  71. if test 2170 -ne `wc -c <'COPYRIGHT'`; then
  72.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  73. fi
  74. # end of 'COPYRIGHT'
  75. fi
  76. if test -f 'FILES' -a "${1}" != "-c" ; then 
  77.   echo shar: Will not clobber existing file \"'FILES'\"
  78. else
  79. echo shar: Extracting \"'FILES'\" \(1824 characters\)
  80. sed "s/^X//" >'FILES' <<'END_OF_FILE'
  81. BLURB
  82. README
  83. XFORMLETTER
  84. SYSCONF
  85. WTF
  86. CALLS
  87. CHANGES
  88. COPYRIGHT
  89. XFILES
  90. OBJECTS
  91. BINARIES
  92. Makefile
  93. TESTS
  94. NEW
  95. NOTES
  96. IMPACT
  97. SECURITY
  98. pty.1
  99. pty-basic.1
  100. pty-opts.1
  101. sess.1
  102. condom.1
  103. QUESTIONS
  104. SESS.draft2
  105. ULOGS.draft1
  106. JOBCTRL.draft3
  107. CTTYS.draft1
  108. CHECKCONF.c
  109. INSTALL.c
  110. argv0.1
  111. argv0.c
  112. biff.1
  113. biff.c
  114. config
  115. checkptys.8
  116. checkptys.c
  117. ctrlv.c
  118. disconnect.1
  119. disconnect.c
  120. env.c
  121. env.h
  122. exclon.1
  123. exclon.c
  124. excloff.c
  125. fmt.c
  126. fmt.h
  127. getopt.c
  128. getopt.h
  129. getoptquiet.c
  130. getoptquiet.h
  131. lock.1
  132. lock.c
  133. mesg.1
  134. mesg.c
  135. nobuf.sh
  136. ptycomm.c
  137. ptycomm.h
  138. ptyerr.c
  139. ptyerr.h
  140. ptyget.c
  141. ptyget.h
  142. ptylogs.c
  143. ptylogs.h
  144. ptymain.c
  145. ptymaster.c
  146. ptymaster.h
  147. ptymisc.c
  148. ptymisc.h
  149. ptysecure.c
  150. ptysecure.h
  151. ptysigler.c
  152. ptysigler.h
  153. ptyslave.c
  154. ptyslave.h
  155. ptytexts.c
  156. ptytexts.h
  157. ptytty.c
  158. ptytty.h
  159. radixsort.3
  160. radixsort.c
  161. radixsort.h
  162. ralloc.c
  163. ralloc.h
  164. reconnect.1
  165. reconnect.c
  166. scan.c
  167. scan.h
  168. sclogrotate.sh
  169. scnowinit.sh
  170. script.1
  171. script.sh
  172. script.tidy.1
  173. script.tidy.sh
  174. sess.sh
  175. sessconnlog.c
  176. sessconnlog.h
  177. sesskill.1
  178. sesskill.c
  179. sesslist.1
  180. sesslist.c
  181. sesslog.c
  182. sesslog.h
  183. sessmenu.1
  184. sessmenu.c
  185. sessname.1
  186. sessname.c
  187. sessnowinit.sh
  188. sessrotate.sh
  189. sesswhere.1
  190. sesswhere.c
  191. sesswho.1
  192. sesswho.c
  193. sigdfl.3
  194. sigdfl.c
  195. sigdfl.h
  196. sigsched.3
  197. sigsched.c
  198. sigsched.h
  199. sod.h
  200. talkacros.7
  201. timer.c
  202. timer.h
  203. tiocsti.1
  204. tiocsti.c
  205. tplay.1
  206. tplay.c
  207. trecord.1
  208. trecord.c
  209. tscript.1
  210. tscript.sh
  211. tty.1
  212. tty.c
  213. ttydetach.1
  214. ttydetach.c
  215. ttydfl.7
  216. ttyprotect.sh
  217. username.c
  218. username.h
  219. users.1
  220. users.c
  221. utmpinit.8
  222. utmpinit.c
  223. waitfor.1
  224. waitfor.c
  225. wall.1
  226. wall.c
  227. who.1
  228. who.c
  229. whoami.1
  230. whoami.c
  231. write.1
  232. write.c
  233. wtmprotate.8
  234. wtmprotate.sh
  235. config/devmty.h
  236. config/devsty.h
  237. config/fdsettrouble.h
  238. config/genericptr.h
  239. config/posix.h
  240. config/ptybin.h
  241. config/ptydir.h
  242. config/ptyext.h
  243. config/ptygroup.h
  244. config/ptylongname.h
  245. config/ptymodes.h
  246. config/ptyopts.h
  247. config/sessconnfile.h
  248. config/sessfile.h
  249. config/sysv.h
  250. config/ttyopts.h
  251. config/utmpfile.h
  252. config/wtmpfile.h
  253. END_OF_FILE
  254. if test 1824 -ne `wc -c <'FILES'`; then
  255.     echo shar: \"'FILES'\" unpacked with wrong size!
  256. fi
  257. # end of 'FILES'
  258. fi
  259. if test -f 'FORMLETTER' -a "${1}" != "-c" ; then 
  260.   echo shar: Will not clobber existing file \"'FORMLETTER'\"
  261. else
  262. echo shar: Extracting \"'FORMLETTER'\" \(826 characters\)
  263. sed "s/^X//" >'FORMLETTER' <<'END_OF_FILE'
  264. To: brnstnd@nyu.edu (Dan Bernstein)
  265. XFrom: 
  266. Date: 
  267. Subject: pty 4.0 FORMLETTER
  268. X
  269. Package: pty 4.0, 2/9/92 release
  270. Obtained from (e.g., uunet.uu.net): 
  271. Obtained by (e.g., ftp): 
  272. X
  273. X1. Machine architecture (e.g., Sun 4/280): 
  274. X2. Operating system (e.g., SunOS 4.1): 
  275. X3. OS vendor (e.g., Sun): 
  276. X4. Does pty work on your machine so far? 
  277. X5. What's CC in your Makefile?
  278. X   CC=
  279. X
  280. X6. If you had to manually edit config/*, what changes did you make?
  281. X   (If you don't remember, here's an easy way out: make CHECKCONF;
  282. X   run CHECKCONF; insert CHECKCONF's output below.)
  283. X
  284. X
  285. X
  286. X7. Describe any problems you've had with pty.
  287. X
  288. X
  289. X
  290. X8. What do you think of the compile/install procedure? SYSCONF,
  291. X   config/*, CHECKCONF, INSTALL, checkptys? How could these be made
  292. X   easier to use?
  293. X
  294. X
  295. X
  296. X9. Any further questions, comments, or suggestions?
  297. X
  298. X
  299. X
  300. Your name:
  301. END_OF_FILE
  302. if test 826 -ne `wc -c <'FORMLETTER'`; then
  303.     echo shar: \"'FORMLETTER'\" unpacked with wrong size!
  304. fi
  305. # end of 'FORMLETTER'
  306. fi
  307. if test -f 'biff.1' -a "${1}" != "-c" ; then 
  308.   echo shar: Will not clobber existing file \"'biff.1'\"
  309. else
  310. echo shar: Extracting \"'biff.1'\" \(957 characters\)
  311. sed "s/^X//" >'biff.1' <<'END_OF_FILE'
  312. X.TH biff 1
  313. X.SH NAME
  314. biff \- be notified if mail arrives and who it is from
  315. X.SH SYNOPSIS
  316. X.B biff
  317. X[
  318. X.B n
  319. X] [
  320. X.B y
  321. X]
  322. X.SH DESCRIPTION
  323. After
  324. X.B biff y,
  325. the system will display
  326. the top of incoming mail on your screen,
  327. as described in
  328. X.B comsat(8).
  329. X.B biff n
  330. turns this off.
  331. X.B biff
  332. applies to your current terminal session;
  333. typically you'd put a
  334. X.B biff y
  335. into your
  336. X.I \&.login,
  337. X.I \&.cshrc,
  338. or
  339. X.I \&.profile.
  340. X
  341. X.B biff
  342. without an argument tells you your current
  343. X``biffing'' status.
  344. X
  345. The mail notification enabled by
  346. X.B biff
  347. operates asynchronously.
  348. XFor synchronous notification use the MAIL variable of
  349. X.B sh (1)
  350. or the mail
  351. variable of
  352. X.B csh (1).
  353. X
  354. X.B biff
  355. requires its input to be your terminal session
  356. X(or at least a session you own). All it really
  357. does is handle the owner-execute bit on the terminal.
  358. X
  359. X.B biff
  360. only looks at the first letter of its first argument.
  361. X
  362. X.B biff
  363. was named after a dog at Berkeley.
  364. X.SH "SEE ALSO"
  365. csh(1),
  366. sh(1),
  367. mail(1),
  368. comsat(8C)
  369. END_OF_FILE
  370. if test 957 -ne `wc -c <'biff.1'`; then
  371.     echo shar: \"'biff.1'\" unpacked with wrong size!
  372. fi
  373. # end of 'biff.1'
  374. fi
  375. if test -f 'condom.1' -a "${1}" != "-c" ; then 
  376.   echo shar: Will not clobber existing file \"'condom.1'\"
  377. else
  378. echo shar: Extracting \"'condom.1'\" \(1755 characters\)
  379. sed "s/^X//" >'condom.1' <<'END_OF_FILE'
  380. X.TH condom 1
  381. X.SH NAME
  382. condom \- wrap a pseudo-terminal around a program
  383. X.SH SYNOPSIS
  384. X.B condom
  385. X.I program
  386. X.B [
  387. X.I arg ...
  388. X.B ]
  389. X
  390. X.B ttyprotect
  391. X.I program
  392. X.B [
  393. X.I arg ...
  394. X.B ]
  395. X.SH DESCRIPTION
  396. X.B condom,
  397. which is really just
  398. X.B pty -0,
  399. runs a program under a pseudo-terminal
  400. with as little interpretation as possible.
  401. X.B ttyprotect
  402. is an alternate name for
  403. X.B condom.
  404. The following are the most noticeable effects of
  405. X.B condom:
  406. X
  407. X1. The
  408. X.B stdio(3)
  409. routines
  410. will, by default,
  411. line-buffer their output rather than
  412. waiting for a big block of output
  413. to accumulate.
  414. X
  415. X2.
  416. X.B condom
  417. always exits with exit code 0,
  418. provided nothing unusual happens.
  419. X
  420. X3.
  421. The original terminal
  422. is always in line-by-line,
  423. echo mode (or whatever mode it is
  424. in originally).
  425. X
  426. X4.
  427. XEnd-of-file
  428. in the input does not result in an end-of-file for
  429. X.I program.
  430. X(This is an inherent and unfortunate restriction
  431. of the current pseudo-terminal design.)
  432. The
  433. X.B nobuf(1)
  434. wrapper does transmit end-of-file.
  435. X
  436. X5.
  437. If
  438. X.I program
  439. refers to /dev/tty,
  440. it will see the pseudo-terminal
  441. X(i.e., its input and output)
  442. rather than its original terminal.
  443. X
  444. X6.
  445. Various signals
  446. to
  447. X.B condom
  448. will be forwarded to
  449. X.I program
  450. as HUPs instead.
  451. X
  452. X.B condom
  453. is most useful for making sure that
  454. X.I program
  455. does not affect the
  456. tty in any strange way,
  457. particularly during debugging.
  458. It is also useful for its effect on buffering:
  459. several
  460. X.B condoms
  461. may appear in a pipeline.
  462. XFor instance,
  463. X
  464. X.EX
  465. last | condom grep phoenix | more
  466. X.EE
  467. X
  468. provides much faster turnaround than the same pipeline without
  469. X.B condom,
  470. as
  471. the
  472. X.B grep
  473. no longer buffers its output.
  474. X
  475. XFor a more complete description of
  476. X.B pty,
  477. see the
  478. X.B pty(1),
  479. X.B pty-basic(1),
  480. and
  481. X.B pty-opts(1)
  482. man pages.
  483. X.SH "SEE ALSO"
  484. pty(1),
  485. pty-basic(1),
  486. pty-opts(1),
  487. setbuf(3),
  488. pty(4)
  489. END_OF_FILE
  490. if test 1755 -ne `wc -c <'condom.1'`; then
  491.     echo shar: \"'condom.1'\" unpacked with wrong size!
  492. fi
  493. # end of 'condom.1'
  494. fi
  495. if test -f 'disconnect.1' -a "${1}" != "-c" ; then 
  496.   echo shar: Will not clobber existing file \"'disconnect.1'\"
  497. else
  498. echo shar: Extracting \"'disconnect.1'\" \(1070 characters\)
  499. sed "s/^X//" >'disconnect.1' <<'END_OF_FILE'
  500. X.TH disconnect 1
  501. X.SH NAME
  502. disconnect \- disconnect current pty session
  503. X.SH SYNOPSIS
  504. X.B disconnect
  505. X[
  506. X.B\-s\fIext
  507. X]
  508. X.SH DESCRIPTION
  509. X.B disconnect
  510. disconnects the current
  511. session,
  512. as if the connection
  513. had been hung up.
  514. Later you can use
  515. X.B reconnect
  516. to get back to the session
  517. exactly where you left off.
  518. X
  519. X.B disconnect
  520. doesn't actually hang up the connection.
  521. If you have previously specified a
  522. X.B reconnect
  523. for the connection,
  524. it will take effect immediately.
  525. X
  526. You can switch rapidly from session
  527. X.I xx
  528. to disconnected session
  529. X.I zz
  530. by typing
  531. X
  532. X.EX
  533. reconnect zz;disconnect
  534. X.EE
  535. X
  536. Then
  537. X.I xx
  538. and
  539. X.I zz
  540. will be reversed,
  541. and you can switch back and forth without trouble.
  542. X
  543. Normally
  544. X.B disconnect
  545. disconnects the session specified by environment variable PTY.
  546. Given
  547. X.B\-s\fIext,
  548. it will instead disconnect session
  549. X.I ext.
  550. X
  551. Note that, unlike the previous version of
  552. X.B disconnect,
  553. this version guarantees that
  554. the session will be disconnected
  555. before it exits,
  556. unless it fails with an error message.
  557. X.SH DIAGNOSTICS
  558. Self-explanatory.
  559. X.SH "SEE ALSO"
  560. pty(1),
  561. sess(1),
  562. reconnect(1)
  563. END_OF_FILE
  564. if test 1070 -ne `wc -c <'disconnect.1'`; then
  565.     echo shar: \"'disconnect.1'\" unpacked with wrong size!
  566. fi
  567. # end of 'disconnect.1'
  568. fi
  569. if test -f 'disconnect.c' -a "${1}" != "-c" ; then 
  570.   echo shar: Will not clobber existing file \"'disconnect.c'\"
  571. else
  572. echo shar: Extracting \"'disconnect.c'\" \(1593 characters\)
  573. sed "s/^X//" >'disconnect.c' <<'END_OF_FILE'
  574. X#include <stdio.h>
  575. X#include "ptymisc.h"
  576. X#include "ptycomm.h"
  577. X#include "config/ptydir.h"
  578. X#include "getopt.h"
  579. X#include "env.h"
  580. X
  581. main(argc,argv)
  582. int argc;
  583. char *argv[];
  584. X{
  585. X int opt;
  586. X int uid;
  587. X char *ext;
  588. X int fdcomm;
  589. X char resp6[6];
  590. X
  591. X uid = getuid();
  592. X ext = env_get("PTY");
  593. X while ((opt = getopt(argc,argv,"s:")) != opteof)
  594. X   switch(opt)
  595. X    {
  596. X     case 's':
  597. X       ext = optarg;
  598. X       break;
  599. X     case '?':
  600. X     default:
  601. X       exit(1);
  602. X    }
  603. X argc -= optind;
  604. X argv += optind;
  605. X
  606. X if (!ext)
  607. X  {
  608. X   fprintf(stderr,"%s: fatal: no -s specified, and PTY not set; are we under a session?\n",optprogname);
  609. X   exit(2);
  610. X  }
  611. X
  612. X if (chdir(PTYDIR) == -1)
  613. X  {
  614. X   fprintf(stderr,"%s: fatal: cannot change to session directory %s\n",optprogname,PTYDIR);
  615. X   exit(2);
  616. X  }
  617. X
  618. X fdcomm = comm_write(ext,uid);
  619. X if (fdcomm == -1)
  620. X  {
  621. X   fprintf(stderr,"%s: fatal: cannot find session %s; if it exists, do you own it?\n",optprogname,ext);
  622. X   exit(2);
  623. X  }
  624. X if (bwrite(fdcomm,"d",1) < 1)
  625. X  {
  626. X   close(fdcomm);
  627. X   fprintf(stderr,"%s: weird: session %s refuses to listen\n",optprogname,ext);
  628. X   exit(2);
  629. X  }
  630. X if (bread(fdcomm,resp6,6) < 6)
  631. X  {
  632. X   close(fdcomm);
  633. X   fprintf(stderr,"%s: weird: session %s refuses to respond\n",optprogname,ext);
  634. X   exit(2);
  635. X  }
  636. X close(fdcomm);
  637. X
  638. X if (respeq(resp6,"kinky!"))
  639. X  {
  640. X   fprintf(stderr,"%s: fatal: pty %s does not support disconnects\n",optprogname,ext);
  641. X   exit(2);
  642. X  }
  643. X if (respeq(resp6,"no-op!"))
  644. X  {
  645. X   fprintf(stderr,"%s: warning: session %s already disconnected\n",optprogname,ext);
  646. X   exit(2);
  647. X  }
  648. X
  649. X if (!respeq(resp6,"yessir"))
  650. X   ; /* unrecognized reply code */
  651. X
  652. X exit(0);
  653. X}
  654. END_OF_FILE
  655. if test 1593 -ne `wc -c <'disconnect.c'`; then
  656.     echo shar: \"'disconnect.c'\" unpacked with wrong size!
  657. fi
  658. # end of 'disconnect.c'
  659. fi
  660. if test -f 'getoptquiet.c' -a "${1}" != "-c" ; then 
  661.   echo shar: Will not clobber existing file \"'getoptquiet.c'\"
  662. else
  663. echo shar: Extracting \"'getoptquiet.c'\" \(1642 characters\)
  664. sed "s/^X//" >'getoptquiet.c' <<'END_OF_FILE'
  665. X/* XXX: this file shouldn't exist */
  666. X
  667. X#include <stdio.h> /* for EOF and stderr---talk about immodularity! */
  668. X#include "getoptquiet.h"
  669. X
  670. int optind = 1;
  671. int optpos = 0;
  672. int opterr = 1;
  673. char *optarg = 0;
  674. int optproblem = 0;
  675. char *optprogname = 0;
  676. int opteof = EOF;
  677. X
  678. int getopt(argc,argv,opts)
  679. int argc;
  680. char **argv;
  681. char *opts;
  682. X{
  683. X int c;
  684. X char *s;
  685. X
  686. X optarg = 0;
  687. X if (!optprogname)
  688. X  {
  689. X   optprogname = *argv;
  690. X   if (!optprogname) /* oh boy */
  691. X     optprogname = ""; /*XXX*/
  692. X   for (s = optprogname;*s;++s)
  693. X     if (*s == '/')
  694. X       optprogname = s + 1;
  695. X  }
  696. X if (!argv || (optind >= argc) || !argv[optind])
  697. X   return opteof;
  698. X while (optpos && !argv[optind][optpos])
  699. X  {
  700. X   /* we simply skip blank arguments... not any more */
  701. X   ++optind;
  702. X   optpos = 0;
  703. X   if ((optind >= argc) || !argv[optind])
  704. X     return opteof;
  705. X  }
  706. X if (!optpos)
  707. X  {
  708. X   if (argv[optind][0] != '-')
  709. X     return opteof;
  710. X   ++optpos;
  711. X   c = argv[optind][1];
  712. X   if ((c == '-') || (c == 0))
  713. X    {
  714. X     /* XXX: this behavior of "-" is stupid */
  715. X     if (c)
  716. X       ++optind;
  717. X     optpos = 0;
  718. X     return opteof;
  719. X    }
  720. X   /* otherwise c is reassigned below */
  721. X  }
  722. X c = argv[optind][optpos];
  723. X ++optpos;
  724. X s = opts;
  725. X while (*s)
  726. X  {
  727. X   if (c == *s)
  728. X    {
  729. X     if (s[1] == ':')
  730. X      {
  731. X       optarg = argv[optind] + optpos;
  732. X       ++optind;
  733. X       optpos = 0;
  734. X       if (!*optarg)
  735. X        {
  736. X         optarg = argv[optind];
  737. X         if ((optind >= argc) || !optarg) /* argument past end */
  738. X          {
  739. X           optproblem = c;
  740. X           return '?';
  741. X          }
  742. X     ++optind;
  743. X        }
  744. X      }
  745. X     return c;
  746. X    }
  747. X   ++s;
  748. X   if (*s == ':')
  749. X     ++s;
  750. X  }
  751. X optproblem = c;
  752. X return '?';
  753. X}
  754. END_OF_FILE
  755. if test 1642 -ne `wc -c <'getoptquiet.c'`; then
  756.     echo shar: \"'getoptquiet.c'\" unpacked with wrong size!
  757. fi
  758. # end of 'getoptquiet.c'
  759. fi
  760. if test -f 'lock.c' -a "${1}" != "-c" ; then 
  761.   echo shar: Will not clobber existing file \"'lock.c'\"
  762. else
  763. echo shar: Extracting \"'lock.c'\" \(990 characters\)
  764. sed "s/^X//" >'lock.c' <<'END_OF_FILE'
  765. X/* lock.c: clone of lock program
  766. Daniel J. Bernstein, brnstnd@nyu.edu.
  767. No dependencies.
  768. Requires curses and signal, i.e., UNIX.
  769. X7/27/91: Baseline. lock 2.0, public domain.
  770. No known patent problems.
  771. X
  772. Documentation in lock.1.
  773. X
  774. Derived from version of lock included with pty 3.0.
  775. X*/
  776. X
  777. X#include <curses.h>
  778. X#include <signal.h>
  779. X
  780. main()
  781. X{
  782. X char key[100];
  783. X char key2[100];
  784. X int i;
  785. X
  786. X for (i = 1;i < 32;++i) /*XXX*/
  787. X   signal(i,SIG_IGN);
  788. X savetty();
  789. X crmode();
  790. X noecho();
  791. X printf("Key: "); fflush(stdout);
  792. X if (fgets(key,sizeof(key) - 2,stdin))
  793. X  {
  794. X   printf("\nAgain: "); fflush(stdout);
  795. X   if (fgets(key2,sizeof(key2) - 2,stdin))
  796. X     if (!strcmp(key,key2))
  797. X      {
  798. X       printf("\n"); fflush(stdout);
  799. X       while ((fgets(key2,sizeof(key2),stdin) == NULL) || strcmp(key,key2))
  800. X    {
  801. X     printf("Bad password!\n");
  802. X     for (i = 0;i < 20;++i)
  803. X       putchar(7);
  804. X     fflush(stdout);
  805. X     sleep(1);
  806. X    }
  807. X      }
  808. X     else printf("\n%c",7);
  809. X   else printf("\n%c",7);
  810. X  }
  811. X else printf("\n%c",7);
  812. X resetty();
  813. X exit(0);
  814. X}
  815. END_OF_FILE
  816. if test 990 -ne `wc -c <'lock.c'`; then
  817.     echo shar: \"'lock.c'\" unpacked with wrong size!
  818. fi
  819. # end of 'lock.c'
  820. fi
  821. if test -f 'ptyerr.c' -a "${1}" != "-c" ; then 
  822.   echo shar: Will not clobber existing file \"'ptyerr.c'\"
  823. else
  824. echo shar: Extracting \"'ptyerr.c'\" \(955 characters\)
  825. sed "s/^X//" >'ptyerr.c' <<'END_OF_FILE'
  826. X#include "getoptquiet.h"
  827. X#include "fmt.h"
  828. X#include "ptyerr.h"
  829. X#include "ralloc.h"
  830. X
  831. void die(n)
  832. int n;
  833. X{
  834. X _exit(n);
  835. X}
  836. X
  837. static int flagwarning = 1;
  838. X
  839. void warn_disable()
  840. X{
  841. X flagwarning = 0;
  842. X}
  843. X
  844. void warn(level,problem)
  845. char *level;
  846. char *problem;
  847. X{
  848. X char *buf;
  849. X
  850. X if (!flagwarning)
  851. X   return;
  852. X if (!optprogname)
  853. X   optprogname = "pty";
  854. X buf = ralloc(strlen(optprogname) + strlen(level) + strlen(problem) + 10);
  855. X if (!buf)
  856. X  {
  857. X   write(2,optprogname,strlen(optprogname));
  858. X   write(2,": ",2);
  859. X   write(2,level,strlen(level));
  860. X   write(2,": ",2);
  861. X   write(2,problem,strlen(problem));
  862. X   write(2,"\r\n",2);
  863. X  }
  864. X else
  865. X  {
  866. X   char *t; t = buf;
  867. X   t += fmt_strncpy(t,optprogname,0);
  868. X   t += fmt_strncpy(t,": ",0);
  869. X   t += fmt_strncpy(t,level,0);
  870. X   t += fmt_strncpy(t,": ",0);
  871. X   t += fmt_strncpy(t,problem,0);
  872. X   t += fmt_strncpy(t,"\r\n",0);
  873. X   *t = 0;
  874. X   write(2,buf,strlen(buf));
  875. X   rfree(buf);
  876. X  }
  877. X}
  878. X
  879. void info(text)
  880. char *text;
  881. X{
  882. X write(2,text,strlen(text));
  883. X}
  884. END_OF_FILE
  885. if test 955 -ne `wc -c <'ptyerr.c'`; then
  886.     echo shar: \"'ptyerr.c'\" unpacked with wrong size!
  887. fi
  888. # end of 'ptyerr.c'
  889. fi
  890. if test -f 'ptylogs.c' -a "${1}" != "-c" ; then 
  891.   echo shar: Will not clobber existing file \"'ptylogs.c'\"
  892. else
  893. echo shar: Extracting \"'ptylogs.c'\" \(2208 characters\)
  894. sed "s/^X//" >'ptylogs.c' <<'END_OF_FILE'
  895. X#include <sys/types.h>
  896. X#include <sys/file.h>
  897. X#include <utmp.h>
  898. X#include "fmt.h"
  899. X#include "config/utmpfile.h"
  900. X#include "config/wtmpfile.h"
  901. X#include "config/sysv.h" /*XXX*/
  902. X#include "ptymisc.h"
  903. X#include "ptylogs.h"
  904. extern int flagxutmp; /*XXX*/
  905. extern int flagxwtmp; /*XXX*/
  906. X
  907. X/* utmp and wtmp make about as much sense as /etc/passwd: not much. */
  908. X
  909. int utmp_on(ext,name,host,date)
  910. char *ext;
  911. char *name;
  912. char *host;
  913. long date;
  914. X{
  915. X struct utmp ut;
  916. X struct utmp xt;
  917. X int fd;
  918. X int i;
  919. X char *t;
  920. X
  921. X if (!flagxutmp)
  922. X   return 0;
  923. X
  924. X /* XXXX: This uses sequential allocation. See utmpinit. */
  925. X
  926. X t = ut.ut_line;
  927. X t += fmt_strncpy(t,"tty",0);
  928. X *t++ = ext[0];
  929. X *t++ = ext[1];
  930. X *t = 0;
  931. X strncpy(ut.ut_name,name,sizeof(ut.ut_name));
  932. X#ifndef SYSV
  933. X strncpy(ut.ut_host,host,sizeof(ut.ut_host));
  934. X#endif
  935. X ut.ut_time = date;
  936. X
  937. X if ((fd = open(UTMP_FILE,O_RDWR)) == -1)
  938. X   return -1;
  939. X
  940. X i = 0;
  941. X while (bread(fd,(char *) &xt,sizeof(xt)) == sizeof(xt)) /* XXX: should buffer */
  942. X  {
  943. X   if (!strncmp(xt.ut_line,ut.ut_line,sizeof(ut.ut_line)))
  944. X    {
  945. X     if (lseek(fd,i * (long) sizeof(xt),L_SET) == -1)
  946. X      {
  947. X       close(fd);
  948. X       return -1;
  949. X      }
  950. X     i = -1;
  951. X     break;
  952. X    }
  953. X   ++i;
  954. X  }
  955. X if (i != -1)
  956. X  {
  957. X   /* We have to reopen to avoid a race with other end-of-utmp entries. */
  958. X   close(fd);
  959. X   if ((fd = open(UTMP_FILE,O_RDWR | O_APPEND)) == -1)
  960. X     return -1;
  961. X  }
  962. X
  963. X if (bwrite(fd,(char *) &ut,sizeof(ut)) < sizeof(ut))
  964. X  {
  965. X   close(fd);
  966. X   return -1;
  967. X  }
  968. X close(fd);
  969. X return 0;
  970. X}
  971. X
  972. int utmp_off(ext,host,date)
  973. char *ext;
  974. char *host;
  975. long date;
  976. X{
  977. X utmp_on(ext,"",host,date);
  978. X}
  979. X
  980. int wtmp_on(ext,name,host,date)
  981. char *ext;
  982. char *name;
  983. char *host;
  984. long date;
  985. X{
  986. X struct utmp wt;
  987. X int fd;
  988. X char *t;
  989. X
  990. X if (!flagxwtmp)
  991. X   return 0;
  992. X
  993. X t = wt.ut_line;
  994. X t += fmt_strncpy(t,"tty",0);
  995. X *t++ = ext[0];
  996. X *t++ = ext[1];
  997. X *t = 0;
  998. X strncpy(wt.ut_name,name,sizeof(wt.ut_name));
  999. X#ifndef SYSV
  1000. X strncpy(wt.ut_host,host,sizeof(wt.ut_host));
  1001. X#endif
  1002. X wt.ut_time = date;
  1003. X
  1004. X if ((fd = open(WTMP_FILE,O_WRONLY | O_APPEND)) == -1)
  1005. X   return -1;
  1006. X if (bwrite(fd,(char *) &wt,sizeof(wt)) < sizeof(wt))
  1007. X  {
  1008. X   close(fd);
  1009. X   return -1;
  1010. X  }
  1011. X close(fd);
  1012. X return 0;
  1013. X}
  1014. X
  1015. int wtmp_off(ext,host,date)
  1016. char *ext;
  1017. char *host;
  1018. long date;
  1019. X{
  1020. X wtmp_on(ext,"",host,date);
  1021. X}
  1022. END_OF_FILE
  1023. if test 2208 -ne `wc -c <'ptylogs.c'`; then
  1024.     echo shar: \"'ptylogs.c'\" unpacked with wrong size!
  1025. fi
  1026. # end of 'ptylogs.c'
  1027. fi
  1028. if test -f 'ptymisc.c' -a "${1}" != "-c" ; then 
  1029.   echo shar: Will not clobber existing file \"'ptymisc.c'\"
  1030. else
  1031. echo shar: Extracting \"'ptymisc.c'\" \(2045 characters\)
  1032. sed "s/^X//" >'ptymisc.c' <<'END_OF_FILE'
  1033. X#include <sys/types.h>
  1034. X#include <sys/file.h>
  1035. X#include <sys/time.h>
  1036. X#include <errno.h>
  1037. extern int errno;
  1038. X#include <fcntl.h>
  1039. X#include "ptymisc.h"
  1040. X#include "config/fdsettrouble.h"
  1041. X
  1042. X#ifdef DESPERATE_FD_SET
  1043. X#undef fd_set
  1044. X#define fd_set long
  1045. X#endif
  1046. X
  1047. extern long time();
  1048. long now()
  1049. X{
  1050. X return time((long *) 0);
  1051. X}
  1052. X
  1053. int gaargh(n) int n;
  1054. X{
  1055. X struct timeval t;
  1056. X
  1057. X t.tv_sec = 0;
  1058. X t.tv_usec = n;
  1059. X return select(0,(fd_set *) 0,(fd_set *) 0,(fd_set *) 0,&t);
  1060. X}
  1061. X
  1062. int setnonblock(fd)
  1063. int fd;
  1064. X{
  1065. X return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | FNDELAY); /* XXX */
  1066. X}
  1067. X
  1068. int unsetnonblock(fd)
  1069. int fd;
  1070. X{
  1071. X return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~FNDELAY); /*XXX*/
  1072. X}
  1073. X
  1074. int forceopen(fd)
  1075. int fd;
  1076. X{
  1077. X int fdnull;
  1078. X if (fcntl(fd,F_GETFL,0) != -1) /* it's open already */
  1079. X   return 0;
  1080. X fdnull = open("/dev/null",O_RDWR,0);
  1081. X if (fdnull == -1)
  1082. X   fdnull = open("/",O_RDONLY,0);
  1083. X if (fdnull == -1)
  1084. X   return -1;
  1085. X if (fdnull != fd)
  1086. X  {
  1087. X   if (dup2(fdnull,fd) == -1)
  1088. X    {
  1089. X     close(fdnull);
  1090. X     return -1;
  1091. X    }
  1092. X   close(fdnull);
  1093. X  }
  1094. X return 0;
  1095. X}
  1096. X
  1097. int respeq(resp,str)
  1098. char *resp;
  1099. char *str;
  1100. X{
  1101. X return scan_strncmp(resp,str,6) == 6;
  1102. X}
  1103. X
  1104. int bread(fd,buf,n)
  1105. int fd; char *buf; int n;
  1106. X{
  1107. X int r; int tot; tot = 0;
  1108. X while (n)
  1109. X  {
  1110. X   r = read(fd,buf,n);
  1111. X   if (r == 0) break;
  1112. X   if (r == -1)
  1113. X     if ((errno == EINTR) || (errno == EWOULDBLOCK)) continue;
  1114. X     else return -1; /* XXX: losing data! */
  1115. X   buf += r; tot += r; n -= r;
  1116. X  }
  1117. X return tot;
  1118. X}
  1119. X
  1120. int bwrite(fd,buf,n)
  1121. int fd; char *buf; int n;
  1122. X{
  1123. X int w; int tot; tot = 0;
  1124. X while (n)
  1125. X  {
  1126. X   w = write(fd,buf,n);
  1127. X   if (w == 0) break; /* XXX: can happen under System V [sigh] */
  1128. X   if (w == -1)
  1129. X     if ((errno == EINTR) || (errno == EWOULDBLOCK)) continue;
  1130. X     else return -1; /* XXX: losing data! */
  1131. X   buf += w; tot += w; n -= w;
  1132. X  }
  1133. X return tot;
  1134. X}
  1135. X
  1136. int lflock(fd)
  1137. int fd;
  1138. X{
  1139. X /* must depend only on write access */
  1140. X /* does not need to disappear automatically upon close() */
  1141. X /* but should disappear automatically upon crash of any sort */
  1142. X return flock(fd,LOCK_EX);
  1143. X}
  1144. X
  1145. int lfunlock(fd)
  1146. int fd;
  1147. X{
  1148. X return flock(fd,LOCK_UN);
  1149. X}
  1150. END_OF_FILE
  1151. if test 2045 -ne `wc -c <'ptymisc.c'`; then
  1152.     echo shar: \"'ptymisc.c'\" unpacked with wrong size!
  1153. fi
  1154. # end of 'ptymisc.c'
  1155. fi
  1156. if test -f 'ptytty.h' -a "${1}" != "-c" ; then 
  1157.   echo shar: Will not clobber existing file \"'ptytty.h'\"
  1158. else
  1159. echo shar: Extracting \"'ptytty.h'\" \(915 characters\)
  1160. sed "s/^X//" >'ptytty.h' <<'END_OF_FILE'
  1161. X#ifndef PTY_TTY_H
  1162. X#define PTY_TTY_H
  1163. X
  1164. X#include "config/ttyopts.h"
  1165. X#include <sys/ioctl.h>
  1166. X#ifdef TTY_TERMIO
  1167. X#include <sys/termio.h>
  1168. X#endif
  1169. X
  1170. struct ttywin
  1171. X {
  1172. X#ifdef TTY_WINDOWS
  1173. X  struct winsize ws;
  1174. X#endif
  1175. X  int dummy;
  1176. X }
  1177. X;
  1178. X
  1179. struct ttymodes
  1180. X {
  1181. X#ifdef TTY_TERMIO
  1182. X  struct termio ti;
  1183. X#else
  1184. X  int di; long lb;
  1185. X  struct sgttyb sg; struct tchars tc; struct ltchars lt;
  1186. X#endif
  1187. X  struct ttywin wi;
  1188. X#ifdef TTY_AUXCHARS
  1189. X  struct auxchars au;
  1190. X#endif
  1191. X }
  1192. X;
  1193. X
  1194. extern int tty_getctrl();
  1195. extern int tty_dissoc();
  1196. extern int tty_spaceleft();
  1197. extern int tty_setexcl();
  1198. extern int tctpgrp();
  1199. X
  1200. extern int tty_getmodes();
  1201. extern int tty_setmodes();
  1202. extern int tty_modifymodes();
  1203. X
  1204. X/* The following don't do any ioctls; they just mangle internal ttymodes. */
  1205. X
  1206. extern void tty_copymodes();
  1207. extern void tty_win2modes();
  1208. extern void tty_modes2win();
  1209. extern void tty_zeromode();
  1210. extern void tty_mungemodes();
  1211. extern void tty_initmodes();
  1212. X
  1213. X#endif
  1214. END_OF_FILE
  1215. if test 915 -ne `wc -c <'ptytty.h'`; then
  1216.     echo shar: \"'ptytty.h'\" unpacked with wrong size!
  1217. fi
  1218. # end of 'ptytty.h'
  1219. fi
  1220. if test -f 'reconnect.1' -a "${1}" != "-c" ; then 
  1221.   echo shar: Will not clobber existing file \"'reconnect.1'\"
  1222. else
  1223. echo shar: Extracting \"'reconnect.1'\" \(1353 characters\)
  1224. sed "s/^X//" >'reconnect.1' <<'END_OF_FILE'
  1225. X.TH reconnect 1
  1226. X.SH NAME
  1227. reconnect \- reconnect to a pty session
  1228. X.SH SYNOPSIS
  1229. X.B reconnect
  1230. X[
  1231. X.B\-s\fIext
  1232. X]
  1233. X.I sn
  1234. X.SH DESCRIPTION
  1235. X.B reconnect
  1236. X.I sn
  1237. means
  1238. X``When this session finishes or is disconnected,
  1239. reconnect to the session named
  1240. X.I sn.''
  1241. This lets you get back to a
  1242. session abandoned by
  1243. X.B disconnect
  1244. or by a previously hung up connection.
  1245. X
  1246. If you are not currently
  1247. under a
  1248. X.B pty
  1249. session,
  1250. or if you would like to reconnect
  1251. immediately without waiting for
  1252. the current session to finish,
  1253. you can use
  1254. X
  1255. X.EX
  1256. sess reconnect sn
  1257. X.EE
  1258. X
  1259. Only the latest
  1260. X.B reconnect
  1261. matters for a given connection.
  1262. If you leave out
  1263. X.I sn,
  1264. the connection will simply drop
  1265. when its association with the
  1266. current session is severed.
  1267. This is the normal behavior.
  1268. X
  1269. Normally
  1270. X.B reconnect
  1271. handles the session specified by environment variable PTY.
  1272. Option
  1273. X.B\-s\fIext
  1274. tells
  1275. X.B reconnect
  1276. to set up a reconnect for session
  1277. X.I ext
  1278. instead.
  1279. X
  1280. Note that, unlike the previous version of
  1281. X.B reconnect,
  1282. this version lets you specify a reconnect to a session
  1283. which does not currently exist.
  1284. If the current session exits or is disconnected
  1285. before the other session is created,
  1286. the reconnection will fail.
  1287. X
  1288. Note that a session's input and output are handled just
  1289. as efficiently after reconnect as before disconnect.
  1290. X.SH DIAGNOSTICS
  1291. Self-explanatory.
  1292. X.SH "SEE ALSO"
  1293. pty(1),
  1294. sess(1),
  1295. disconnect(1)
  1296. END_OF_FILE
  1297. if test 1353 -ne `wc -c <'reconnect.1'`; then
  1298.     echo shar: \"'reconnect.1'\" unpacked with wrong size!
  1299. fi
  1300. # end of 'reconnect.1'
  1301. fi
  1302. if test -f 'reconnect.c' -a "${1}" != "-c" ; then 
  1303.   echo shar: Will not clobber existing file \"'reconnect.c'\"
  1304. else
  1305. echo shar: Extracting \"'reconnect.c'\" \(1812 characters\)
  1306. sed "s/^X//" >'reconnect.c' <<'END_OF_FILE'
  1307. X#include <stdio.h>
  1308. X#include "ptymisc.h"
  1309. X#include "ptycomm.h"
  1310. X#include "config/ptydir.h"
  1311. X#include "getopt.h"
  1312. X#include "env.h"
  1313. X
  1314. char noreco[2] = { 0, 0 };
  1315. X
  1316. main(argc,argv)
  1317. int argc;
  1318. char *argv[];
  1319. X{
  1320. X int opt;
  1321. X int uid;
  1322. X char *ext;
  1323. X char *reco;
  1324. X int fdcomm;
  1325. X char resp6[6];
  1326. X
  1327. X uid = getuid();
  1328. X ext = env_get("PTY");
  1329. X while ((opt = getopt(argc,argv,"s:")) != opteof)
  1330. X   switch(opt)
  1331. X    {
  1332. X     case 's':
  1333. X       ext = optarg;
  1334. X       break;
  1335. X     case '?':
  1336. X     default:
  1337. X       exit(1);
  1338. X    }
  1339. X argc -= optind;
  1340. X argv += optind;
  1341. X
  1342. X if (!ext)
  1343. X  {
  1344. X   fprintf(stderr,"%s: fatal: no -s specified, and PTY not set; are we under a session?\n",optprogname);
  1345. X   exit(2);
  1346. X  }
  1347. X
  1348. X reco = *argv;
  1349. X if (!reco)
  1350. X   reco = noreco;
  1351. X
  1352. X if (chdir(PTYDIR) == -1)
  1353. X  {
  1354. X   fprintf(stderr,"%s: fatal: cannot change to session directory %s\n",optprogname,PTYDIR);
  1355. X   exit(2);
  1356. X  }
  1357. X
  1358. X fdcomm = comm_write(ext,uid);
  1359. X if (fdcomm == -1)
  1360. X  {
  1361. X   fprintf(stderr,"%s: fatal: cannot find session %s; if it exists, do you own it?\n",optprogname,ext);
  1362. X   exit(2);
  1363. X  }
  1364. X if (bwrite(fdcomm,"s",1) < 1)
  1365. X  {
  1366. X   close(fdcomm);
  1367. X   fprintf(stderr,"%s: weird: session %s refuses to listen\n",optprogname,ext);
  1368. X   exit(2);
  1369. X  }
  1370. X if (bwrite(fdcomm,reco,2) < 2)
  1371. X  {
  1372. X   close(fdcomm);
  1373. X   fprintf(stderr,"%s: weird: session %s refuses to listen\n",optprogname,ext);
  1374. X   exit(2);
  1375. X  }
  1376. X if (bread(fdcomm,resp6,6) < 6)
  1377. X  {
  1378. X   close(fdcomm);
  1379. X   fprintf(stderr,"%s: weird: session %s refuses to respond\n",optprogname,ext);
  1380. X   exit(2);
  1381. X  }
  1382. X close(fdcomm);
  1383. X
  1384. X if (respeq(resp6,"nosglr"))
  1385. X  {
  1386. X   fprintf(stderr,"%s: fatal: session %s not connected\n",optprogname,ext);
  1387. X   exit(2);
  1388. X  }
  1389. X
  1390. X if (!respeq(resp6,"sglrok"))
  1391. X   ; /* unrecognized reply code */
  1392. X
  1393. X fprintf(stderr,"%s: will connect to session %c%c when session %c%c is done\n"
  1394. X   ,optprogname,reco[0],reco[1],ext[0],ext[1]);
  1395. X exit(0);
  1396. X}
  1397. END_OF_FILE
  1398. if test 1812 -ne `wc -c <'reconnect.c'`; then
  1399.     echo shar: \"'reconnect.c'\" unpacked with wrong size!
  1400. fi
  1401. # end of 'reconnect.c'
  1402. fi
  1403. if test -f 'script.1' -a "${1}" != "-c" ; then 
  1404.   echo shar: Will not clobber existing file \"'script.1'\"
  1405. else
  1406. echo shar: Extracting \"'script.1'\" \(1108 characters\)
  1407. sed "s/^X//" >'script.1' <<'END_OF_FILE'
  1408. X.TH script 1
  1409. X.SH NAME
  1410. script \- make typescript of terminal session
  1411. X.SH SYNOPSIS
  1412. X.B script
  1413. X[
  1414. X.B \-a
  1415. X] [
  1416. X.I file
  1417. X]
  1418. X.SH DESCRIPTION
  1419. X.B script
  1420. makes a typescript of everything printed on your terminal.
  1421. The typescript is written to
  1422. X.I file,
  1423. or appended to
  1424. X.I file
  1425. if the
  1426. X.B \-a
  1427. option is given.
  1428. You can print it later with
  1429. X.B lpr.
  1430. If you don't give a filename,
  1431. the typescript is saved in the file
  1432. X.I typescript.
  1433. X
  1434. Actually,
  1435. this clone version of
  1436. X.B script
  1437. just passes its options through to
  1438. X.B tee,
  1439. so you can list multiple files if you want.
  1440. X
  1441. X.B script
  1442. runs whatever shell is in environment variable
  1443. X.I SHELL,
  1444. default /bin/sh.
  1445. This clone version uses
  1446. X.B pty
  1447. to allocate a pseudo-terminal,
  1448. so the session is listed in
  1449. X.I /etc/utmp,
  1450. and lots of things work right that
  1451. didn't work in the original.
  1452. XFor example:
  1453. X.B talk(1)
  1454. works;
  1455. X.B mail(1)
  1456. works;
  1457. you can stop and restart the shell,
  1458. with
  1459. X.B control-Z
  1460. in
  1461. X.I sh
  1462. or
  1463. X.B suspend
  1464. in
  1465. X.I csh;
  1466. and so on.
  1467. X
  1468. The script ends when the forked shell exits.
  1469. This clone version is more careful than the original to
  1470. let every last bit of output appear.
  1471. X.SH "SEE ALSO"
  1472. script.tidy(1)
  1473. END_OF_FILE
  1474. if test 1108 -ne `wc -c <'script.1'`; then
  1475.     echo shar: \"'script.1'\" unpacked with wrong size!
  1476. fi
  1477. # end of 'script.1'
  1478. fi
  1479. if test -f 'sess.1' -a "${1}" != "-c" ; then 
  1480.   echo shar: Will not clobber existing file \"'sess.1'\"
  1481. else
  1482. echo shar: Extracting \"'sess.1'\" \(1160 characters\)
  1483. sed "s/^X//" >'sess.1' <<'END_OF_FILE'
  1484. X.TH sess 1
  1485. X.SH NAME
  1486. sess \- run a program under a disconnectable pty session
  1487. X.SH SYNOPSIS
  1488. X.B sess
  1489. X.I program
  1490. X.B [
  1491. X.I arg ...
  1492. X.B ]
  1493. X.SH DESCRIPTION
  1494. X.B sess,
  1495. which is really just
  1496. X.B pty -s,
  1497. runs a program under a pseudo-terminal
  1498. session that can be easily disconnected and reconnected.
  1499. The session can even be reconnected into the middle of a pipe.
  1500. X
  1501. See
  1502. X.B pty(1),
  1503. X.B pty-basic(1),
  1504. and
  1505. X.B pty-opts(1)
  1506. for a description of
  1507. X.B pty
  1508. and its options.
  1509. X
  1510. X.B sess
  1511. enters the user into
  1512. X/etc/utmp by default;
  1513. this can be turned off with
  1514. X.B\-xU.
  1515. X
  1516. When
  1517. X.B sess
  1518. receives a HUP signal,
  1519. i.e., when the connection is manually hung up,
  1520. it disconnects
  1521. X.I program
  1522. from the outside world
  1523. and waits for a
  1524. X.B reconnect.
  1525. You can manually disconnect a session with
  1526. X.B disconnect.
  1527. X
  1528. Sessions are named by
  1529. their pseudo-terminal extension:
  1530. for example,
  1531. a session under /dev/ttyp5
  1532. has name p5.
  1533. You can use
  1534. X.B sessname
  1535. to give them more descriptive names,
  1536. printed by
  1537. X.B sesslist.
  1538. X
  1539. See
  1540. X``An introduction to session management''
  1541. for a more complete description of the
  1542. session manager interface.
  1543. X.SH "SEE ALSO"
  1544. pty(1),
  1545. condom(1),
  1546. disconnect(1),
  1547. reconnect(1),
  1548. sessname(1),
  1549. sesskill(1),
  1550. sesslist(1)
  1551. END_OF_FILE
  1552. if test 1160 -ne `wc -c <'sess.1'`; then
  1553.     echo shar: \"'sess.1'\" unpacked with wrong size!
  1554. fi
  1555. # end of 'sess.1'
  1556. fi
  1557. if test -f 'sessconnlog.c' -a "${1}" != "-c" ; then 
  1558.   echo shar: Will not clobber existing file \"'sessconnlog.c'\"
  1559. else
  1560. echo shar: Extracting \"'sessconnlog.c'\" \(1688 characters\)
  1561. sed "s/^X//" >'sessconnlog.c' <<'END_OF_FILE'
  1562. X#include <sys/types.h>
  1563. X#include <sys/file.h>
  1564. X#include "sessconnlog.h"
  1565. X#include "ptymisc.h"
  1566. X#include "config/sessconnfile.h"
  1567. X#include "config/ptyext.h"
  1568. X
  1569. static int flagsessconnlog = 1;
  1570. X
  1571. void sessconnlog_disable()
  1572. X{
  1573. X flagsessconnlog = 0;
  1574. X}
  1575. X
  1576. int sessconnlog(sl)
  1577. struct sessconnlog *sl;
  1578. X{
  1579. X int fdnow;
  1580. X int fd;
  1581. X int x;
  1582. X char *s;
  1583. X
  1584. X if (!flagsessconnlog)
  1585. X   return 0;
  1586. X for (x = 0,s = PTYEXT1;*s;++s,x += (sizeof(PTYEXT2) - 1))
  1587. X   if (*s == sl->ext[0])
  1588. X    {
  1589. X     for (s = PTYEXT2;*s;++s,++x)
  1590. X       if (*s == sl->ext[1])
  1591. X    {
  1592. X     fdnow = open(SESSCONNNOW_FILE,O_WRONLY | O_CREAT,0644);
  1593. X     if (fdnow == -1)
  1594. X       return -1;
  1595. X         if (lseek(fdnow,x * (long) sizeof(*sl),L_SET) == -1)
  1596. X      {
  1597. X       close(fdnow);
  1598. X       return -1;
  1599. X      }
  1600. X     if (write(fdnow,(char *) sl,sizeof(*sl)) < sizeof(*sl))
  1601. X      {
  1602. X       close(fdnow); /* XXX: but now sessconnnow is messed up! */
  1603. X       return -1;
  1604. X      }
  1605. X     lflock(fdnow);
  1606. X     fd = open(SESSCONNLOG_FILE,O_WRONLY | O_APPEND | O_CREAT,0644);
  1607. X     if (fd == -1)
  1608. X      {
  1609. X       lfunlock(fdnow);
  1610. X       close(fdnow);
  1611. X       return -1; /* XXX: but now sessconnnow is messed up! */
  1612. X      }
  1613. X     if (write(fd,(char *) sl,sizeof(*sl)) < sizeof(*sl))
  1614. X      {
  1615. X       lfunlock(fdnow);
  1616. X       close(fdnow);
  1617. X       close(fd);
  1618. X       return -1; /* XXX: but now both logs are messed up! */
  1619. X      }
  1620. X     close(fd);
  1621. X     lfunlock(fdnow);
  1622. X     close(fdnow);
  1623. X     return 0;
  1624. X    }
  1625. X     return -1;
  1626. X    }
  1627. X return -1;
  1628. X}
  1629. X
  1630. void sessconnlog_fill(sl,ext,remote,siglerpid,date)
  1631. struct sessconnlog *sl;
  1632. char *ext;
  1633. char *remote;
  1634. int siglerpid;
  1635. long date;
  1636. X{
  1637. X sl->ext[0] = ext[0];
  1638. X sl->ext[1] = ext[1];
  1639. X sl->ext[2] = ext[2]; /* requires SESSCONNLOG_EXTLEN be at least 3 */
  1640. X strncpy(sl->remote,remote,SESSCONNLOG_REMOTELEN);
  1641. X sl->siglerpid = siglerpid;
  1642. X sl->date = date;
  1643. X}
  1644. END_OF_FILE
  1645. if test 1688 -ne `wc -c <'sessconnlog.c'`; then
  1646.     echo shar: \"'sessconnlog.c'\" unpacked with wrong size!
  1647. fi
  1648. # end of 'sessconnlog.c'
  1649. fi
  1650. if test -f 'sesskill.1' -a "${1}" != "-c" ; then 
  1651.   echo shar: Will not clobber existing file \"'sesskill.1'\"
  1652. else
  1653. echo shar: Extracting \"'sesskill.1'\" \(865 characters\)
  1654. sed "s/^X//" >'sesskill.1' <<'END_OF_FILE'
  1655. X.TH sesskill 1
  1656. X.SH NAME
  1657. sesskill \- kill current pty session
  1658. X.SH SYNOPSIS
  1659. X.B sesskill
  1660. X[
  1661. X.B\-ym
  1662. X] [
  1663. X.B\-s\fIext
  1664. X]
  1665. X.SH DESCRIPTION
  1666. X.B sesskill
  1667. kills the current session.
  1668. X.B pty
  1669. will exit immediately,
  1670. throwing away any final output,
  1671. and any process running under the
  1672. pseudo-tty will receive a HUP signal.
  1673. X
  1674. Normally
  1675. X.B sesskill
  1676. kills the session specified by environment variable PTY.
  1677. Given
  1678. X.B\-s\fIext,
  1679. it will instead kill session
  1680. X.I ext.
  1681. X
  1682. Note that, unlike the previous version of
  1683. X.B sesskill,
  1684. this version can be applied
  1685. to a connected session, a session
  1686. where the slave process is still running,
  1687. and even a non-session running under
  1688. X.B pty.
  1689. It is very destructive.
  1690. It will, in fact, not take effect unless you specify
  1691. X.B\-y.
  1692. It will not take effect for the current session unless
  1693. you specify
  1694. X.B\-m.
  1695. X.SH DIAGNOSTICS
  1696. Self-explanatory.
  1697. X.SH "SEE ALSO"
  1698. pty(1),
  1699. sess(1)
  1700. END_OF_FILE
  1701. if test 865 -ne `wc -c <'sesskill.1'`; then
  1702.     echo shar: \"'sesskill.1'\" unpacked with wrong size!
  1703. fi
  1704. # end of 'sesskill.1'
  1705. fi
  1706. if test -f 'sesskill.c' -a "${1}" != "-c" ; then 
  1707.   echo shar: Will not clobber existing file \"'sesskill.c'\"
  1708. else
  1709. echo shar: Extracting \"'sesskill.c'\" \(1733 characters\)
  1710. sed "s/^X//" >'sesskill.c' <<'END_OF_FILE'
  1711. X#include <stdio.h>
  1712. X#include "ptycomm.h"
  1713. X#include "config/ptydir.h"
  1714. X#include "getopt.h"
  1715. X#include "env.h"
  1716. X
  1717. main(argc,argv)
  1718. int argc;
  1719. char *argv[];
  1720. X{
  1721. X int opt;
  1722. X int uid;
  1723. X char *ext;
  1724. X int fdcomm;
  1725. X char resp6[6];
  1726. X int yes;
  1727. X int me;
  1728. X
  1729. X yes = 0;
  1730. X me = 0;
  1731. X
  1732. X uid = getuid();
  1733. X ext = env_get("PTY");
  1734. X while ((opt = getopt(argc,argv,"s:ym")) != opteof)
  1735. X   switch(opt)
  1736. X    {
  1737. X     case 'm':
  1738. X       me = 1;
  1739. X       break;
  1740. X     case 'y':
  1741. X       yes = 1;
  1742. X       break;
  1743. X     case 's':
  1744. X       ext = optarg;
  1745. X       break;
  1746. X     case '?':
  1747. X     default:
  1748. X       exit(1);
  1749. X    }
  1750. X argc -= optind;
  1751. X argv += optind;
  1752. X
  1753. X if (!ext)
  1754. X  {
  1755. X   fprintf(stderr,"%s: fatal: no -s specified, and PTY not set; are we under a session?\n",optprogname);
  1756. X   exit(2);
  1757. X  }
  1758. X if (!yes)
  1759. X  {
  1760. X   fprintf(stderr,"%s: fatal: -y not specified, so no action taken\n",optprogname);
  1761. X   exit(2);
  1762. X  }
  1763. X if (!me && env_get("PTY") && (!strcmp(ext,env_get("PTY"))))
  1764. X  {
  1765. X   fprintf(stderr,"%s: fatal: that session is us, and -m not specified, so no action taken\n",optprogname);
  1766. X   exit(2);
  1767. X  }
  1768. X
  1769. X if (chdir(PTYDIR) == -1)
  1770. X  {
  1771. X   fprintf(stderr,"%s: fatal: cannot change to session directory %s\n",optprogname,PTYDIR);
  1772. X   exit(2);
  1773. X  }
  1774. X
  1775. X fdcomm = comm_write(ext,uid);
  1776. X if (fdcomm == -1)
  1777. X  {
  1778. X   fprintf(stderr,"%s: fatal: cannot find session %s; if it exists, do you own it?\n",optprogname,ext);
  1779. X   exit(2);
  1780. X  }
  1781. X if (write(fdcomm,"k",1) < 1)
  1782. X  {
  1783. X   close(fdcomm);
  1784. X   fprintf(stderr,"%s: weird: session %s refuses to listen\n",optprogname,ext);
  1785. X   exit(2);
  1786. X  }
  1787. X if (read(fdcomm,resp6,6) < 6)
  1788. X  {
  1789. X   close(fdcomm);
  1790. X   fprintf(stderr,"%s: weird: session %s refuses to respond\n",optprogname,ext);
  1791. X   exit(2);
  1792. X  }
  1793. X close(fdcomm);
  1794. X
  1795. X if (!respeq(resp6,"<poof>"))
  1796. X   ; /* unrecognized reply code */
  1797. X
  1798. X exit(0);
  1799. X}
  1800. END_OF_FILE
  1801. if test 1733 -ne `wc -c <'sesskill.c'`; then
  1802.     echo shar: \"'sesskill.c'\" unpacked with wrong size!
  1803. fi
  1804. # end of 'sesskill.c'
  1805. fi
  1806. if test -f 'sesslog.c' -a "${1}" != "-c" ; then 
  1807.   echo shar: Will not clobber existing file \"'sesslog.c'\"
  1808. else
  1809. echo shar: Extracting \"'sesslog.c'\" \(1688 characters\)
  1810. sed "s/^X//" >'sesslog.c' <<'END_OF_FILE'
  1811. X#include <sys/types.h>
  1812. X#include <sys/file.h>
  1813. X#include "sesslog.h"
  1814. X#include "ptymisc.h"
  1815. X#include "config/sessfile.h"
  1816. X#include "config/ptyext.h"
  1817. X
  1818. static int flagsesslog = 1;
  1819. X
  1820. void sesslog_disable()
  1821. X{
  1822. X flagsesslog = 0;
  1823. X}
  1824. X
  1825. int sesslog(sl)
  1826. struct sesslog *sl;
  1827. X{
  1828. X int fdnow;
  1829. X int fd;
  1830. X int x;
  1831. X char *s;
  1832. X
  1833. X if (!flagsesslog)
  1834. X   return 0;
  1835. X for (x = 0,s = PTYEXT1;*s;++s,x += (sizeof(PTYEXT2) - 1))
  1836. X   if (*s == sl->ext[0])
  1837. X    {
  1838. X     for (s = PTYEXT2;*s;++s,++x)
  1839. X       if (*s == sl->ext[1])
  1840. X    {
  1841. X     fdnow = open(SESSNOW_FILE,O_WRONLY | O_CREAT,0644);
  1842. X     if (fdnow == -1)
  1843. X       return -1;
  1844. X         if (lseek(fdnow,x * (long) sizeof(*sl),L_SET) == -1)
  1845. X      {
  1846. X       close(fdnow);
  1847. X       return -1;
  1848. X      }
  1849. X     if (write(fdnow,(char *) sl,sizeof(*sl)) < sizeof(*sl))
  1850. X      {
  1851. X       close(fdnow); /* XXX: but now sessnow is messed up! */
  1852. X       return -1;
  1853. X      }
  1854. X     lflock(fdnow); /* XXX: what if it fails? */
  1855. X     fd = open(SESSLOG_FILE,O_WRONLY | O_APPEND | O_CREAT,0644);
  1856. X     if (fd == -1)
  1857. X      {
  1858. X       lfunlock(fdnow);
  1859. X       close(fdnow);
  1860. X       return -1; /* XXX: but now sessnow is messed up! */
  1861. X      }
  1862. X     if (write(fd,(char *) sl,sizeof(*sl)) < sizeof(*sl))
  1863. X      {
  1864. X       lfunlock(fdnow);
  1865. X       close(fdnow);
  1866. X       close(fd);
  1867. X       return -1; /* XXX: but now both logs are messed up! */
  1868. X      }
  1869. X     close(fd);
  1870. X     lfunlock(fdnow);
  1871. X     close(fdnow);
  1872. X     return 0;
  1873. X    }
  1874. X     return -1;
  1875. X    }
  1876. X return -1;
  1877. X}
  1878. X
  1879. void sesslog_fill(sl,ext,username,uid,masterpid,date)
  1880. struct sesslog *sl;
  1881. char *ext;
  1882. char *username;
  1883. int uid;
  1884. int masterpid;
  1885. long date;
  1886. X{
  1887. X sl->ext[0] = ext[0];
  1888. X sl->ext[1] = ext[1];
  1889. X sl->ext[2] = ext[2]; /* requires SESSLOG_EXTLEN be at least 3 */
  1890. X strncpy(sl->username,username,SESSLOG_USERLEN);
  1891. X sl->uid = uid;
  1892. X sl->masterpid = masterpid;
  1893. X sl->date = date;
  1894. X}
  1895. END_OF_FILE
  1896. if test 1688 -ne `wc -c <'sesslog.c'`; then
  1897.     echo shar: \"'sesslog.c'\" unpacked with wrong size!
  1898. fi
  1899. # end of 'sesslog.c'
  1900. fi
  1901. if test -f 'sesswhere.1' -a "${1}" != "-c" ; then 
  1902.   echo shar: Will not clobber existing file \"'sesswhere.1'\"
  1903. else
  1904. echo shar: Extracting \"'sesswhere.1'\" \(1049 characters\)
  1905. sed "s/^X//" >'sesswhere.1' <<'END_OF_FILE'
  1906. X.TH sesswhere 1
  1907. X.SH NAME
  1908. sesswhere \- list connections to pty sessions on the system
  1909. X.SH SYNOPSIS
  1910. X.B sesswhere
  1911. X[
  1912. X.B\-rRlL
  1913. X] [
  1914. X.B\-f\fIfile
  1915. X]
  1916. X.SH DESCRIPTION
  1917. X.B sesswhere
  1918. lists all
  1919. X.B pty
  1920. sessions on the system,
  1921. one per line,
  1922. including the network addresses they are connected to.
  1923. X
  1924. Normally
  1925. X.B sesswhere
  1926. uses the current session-connection log,
  1927. typically /usr/adm/scnow.
  1928. Under the
  1929. X.B\-f\fIfile
  1930. option
  1931. it will use
  1932. X.I file
  1933. instead.
  1934. X
  1935. The
  1936. X.B\-r
  1937. option
  1938. tells
  1939. X.B sesswhere
  1940. to list the lines in reverse order.
  1941. This is most commonly used with
  1942. X.B\-f.
  1943. X.B\-R
  1944. is the default.
  1945. X
  1946. Given the
  1947. X.B\-l
  1948. option,
  1949. X.B sesswhere
  1950. also shows
  1951. terminal lines without active
  1952. X.B pty
  1953. sessions.
  1954. X.B\-L
  1955. is the default.
  1956. X
  1957. Note that, in the default configuration, the owner
  1958. of a
  1959. X.B pty
  1960. session can control the information reported
  1961. by
  1962. X.B sesswhere,
  1963. so the output should not be used for security analysis.
  1964. X.B sesswhere
  1965. will always
  1966. print control characters visibly.
  1967. X
  1968. The system administrator may disable or restrict use of
  1969. X.B sesswhere.
  1970. X.SH "SEE ALSO"
  1971. pty(1),
  1972. sess(1),
  1973. sesswho(1),
  1974. sesslist(1)
  1975. END_OF_FILE
  1976. if test 1049 -ne `wc -c <'sesswhere.1'`; then
  1977.     echo shar: \"'sesswhere.1'\" unpacked with wrong size!
  1978. fi
  1979. # end of 'sesswhere.1'
  1980. fi
  1981. if test -f 'sesswhere.c' -a "${1}" != "-c" ; then 
  1982.   echo shar: Will not clobber existing file \"'sesswhere.c'\"
  1983. else
  1984. echo shar: Extracting \"'sesswhere.c'\" \(1808 characters\)
  1985. sed "s/^X//" >'sesswhere.c' <<'END_OF_FILE'
  1986. X#include <stdio.h>
  1987. X#include "fmt.h"
  1988. X#include "getopt.h"
  1989. X#include "sessconnlog.h"
  1990. X#include "config/sessconnfile.h"
  1991. X
  1992. main(argc,argv)
  1993. int argc;
  1994. char *argv[];
  1995. X{
  1996. X FILE *fisf;
  1997. X struct sessconnlog sl;
  1998. X int opt;
  1999. X char *file;
  2000. X int flaglogouts;
  2001. X int flagreverse;
  2002. X int revnum;
  2003. X
  2004. X file = SESSCONNNOW_FILE;
  2005. X flaglogouts = 0;
  2006. X flagreverse = 0;
  2007. X
  2008. X while ((opt = getopt(argc,argv,"rRlLf:")) != opteof)
  2009. X   switch(opt)
  2010. X    {
  2011. X     case 'R':
  2012. X       flagreverse = 1;
  2013. X       break;
  2014. X     case 'r':
  2015. X       flagreverse = 1;
  2016. X       break;
  2017. X     case 'l':
  2018. X       flaglogouts = 1;
  2019. X       break;
  2020. X     case 'L':
  2021. X       flaglogouts = 0;
  2022. X       break;
  2023. X     case 'f':
  2024. X       file = optarg;
  2025. X       break;
  2026. X     case '?':
  2027. X     default:
  2028. X       exit(1);
  2029. X    }
  2030. X
  2031. X fisf = fopen(file,"r");
  2032. X if (!fisf)
  2033. X  {
  2034. X   perror("sesswhere: fatal: cannot open current session-connection file");
  2035. X   exit(2);
  2036. X  }
  2037. X if (flagreverse)
  2038. X  {
  2039. X   fseek(fisf,0,2);
  2040. X   revnum = ftell(fisf) / sizeof(sl);
  2041. X   fseek(fisf,sizeof(sl) * --revnum,0);
  2042. X  }
  2043. X
  2044. X while (fread(&sl,sizeof(sl),1,fisf) == 1)
  2045. X  {
  2046. X   static char outbuf[SESSCONNLOG_REMOTELEN + 100];
  2047. X   if (sl.ext[0] && (sl.siglerpid || flaglogouts))
  2048. X    {
  2049. X     char *t; t = outbuf;
  2050. X     *t++ = sl.ext[0]; *t++ = sl.ext[1];
  2051. X     t += fmt_strncpy(t,"  ",0);
  2052. X     t += fmt_strncpy(t,asctime(localtime(&sl.date)) + 4,12);
  2053. X     switch(sl.siglerpid)
  2054. X      {
  2055. X       case -1:
  2056. X     t += fmt_strncpy(t,"  connect ",0);
  2057. X     t += fmt_vis(t,sl.remote,strlen(sl.remote));
  2058. X     break;
  2059. X       case 1:
  2060. X     t += fmt_strncpy(t,"  disconnect",0);
  2061. X     break;
  2062. X       case 0:
  2063. X     t += fmt_strncpy(t,"  cleanup",0);
  2064. X     break;
  2065. X      }
  2066. X     *t++ = '\n';
  2067. X     *t = 0;
  2068. X     fwrite(outbuf,1,t - outbuf,stdout);
  2069. X    }
  2070. X   if (flagreverse)
  2071. X    {
  2072. X     if (fseek(fisf,-2 * sizeof(sl),1) == -1) /*XXX*/
  2073. X       break;
  2074. X     --revnum; /*XXX: why do we care? */
  2075. X    }
  2076. X  }
  2077. X exit(0);
  2078. X}
  2079. END_OF_FILE
  2080. if test 1808 -ne `wc -c <'sesswhere.c'`; then
  2081.     echo shar: \"'sesswhere.c'\" unpacked with wrong size!
  2082. fi
  2083. # end of 'sesswhere.c'
  2084. fi
  2085. if test -f 'sesswho.1' -a "${1}" != "-c" ; then 
  2086.   echo shar: Will not clobber existing file \"'sesswho.1'\"
  2087. else
  2088. echo shar: Extracting \"'sesswho.1'\" \(798 characters\)
  2089. sed "s/^X//" >'sesswho.1' <<'END_OF_FILE'
  2090. X.TH sesswho 1
  2091. X.SH NAME
  2092. sesswho \- list all pty sessions on the system
  2093. X.SH SYNOPSIS
  2094. X.B sesswho
  2095. X[
  2096. X.B\-rRlL
  2097. X] [
  2098. X.B\-f\fIfile
  2099. X]
  2100. X.SH DESCRIPTION
  2101. X.B sesswho
  2102. lists all
  2103. X.B pty
  2104. sessions on the system,
  2105. one per line,
  2106. with owners and master process ids.
  2107. X
  2108. Normally
  2109. X.B sesswho
  2110. uses the current session log,
  2111. typically /usr/adm/sessnow.
  2112. Under the
  2113. X.B\-f\fIfile
  2114. option
  2115. it will use
  2116. X.I file
  2117. instead.
  2118. X
  2119. The
  2120. X.B\-r
  2121. option
  2122. tells
  2123. X.B sesswho
  2124. to list the lines in reverse order.
  2125. This is most commonly used with
  2126. X.B\-f.
  2127. X.B\-R
  2128. is the default.
  2129. X
  2130. Given the
  2131. X.B\-l
  2132. option,
  2133. X.B sesswho
  2134. also shows
  2135. terminal lines without active
  2136. X.B pty
  2137. sessions.
  2138. This shows when those sessions terminated.
  2139. X.B\-L
  2140. is the default.
  2141. X
  2142. The system administrator may disable or restrict use of
  2143. X.B sesswho.
  2144. X.SH "SEE ALSO"
  2145. pty(1),
  2146. sess(1),
  2147. sesswhere(1),
  2148. sesslist(1)
  2149. END_OF_FILE
  2150. if test 798 -ne `wc -c <'sesswho.1'`; then
  2151.     echo shar: \"'sesswho.1'\" unpacked with wrong size!
  2152. fi
  2153. # end of 'sesswho.1'
  2154. fi
  2155. if test -f 'sesswho.c' -a "${1}" != "-c" ; then 
  2156.   echo shar: Will not clobber existing file \"'sesswho.c'\"
  2157. else
  2158. echo shar: Extracting \"'sesswho.c'\" \(1539 characters\)
  2159. sed "s/^X//" >'sesswho.c' <<'END_OF_FILE'
  2160. X#include <stdio.h>
  2161. X#include "getopt.h"
  2162. X#include "sesslog.h"
  2163. X#include "config/sessfile.h" /* XXX: maybe sesslog should have an iterator? */
  2164. X
  2165. main(argc,argv)
  2166. int argc;
  2167. char *argv[];
  2168. X{
  2169. X FILE *fisf;
  2170. X struct sesslog sl;
  2171. X int opt;
  2172. X char *file;
  2173. X int flaglogouts;
  2174. X int flagreverse;
  2175. X int revnum;
  2176. X
  2177. X file = SESSNOW_FILE;
  2178. X flaglogouts = 0;
  2179. X flagreverse = 0;
  2180. X
  2181. X while ((opt = getopt(argc,argv,"rRlLf:")) != opteof)
  2182. X   switch(opt)
  2183. X    {
  2184. X     case 'R':
  2185. X       flagreverse = 1;
  2186. X       break;
  2187. X     case 'r':
  2188. X       flagreverse = 1;
  2189. X       break;
  2190. X     case 'l':
  2191. X       flaglogouts = 1;
  2192. X       break;
  2193. X     case 'L':
  2194. X       flaglogouts = 0;
  2195. X       break;
  2196. X     case 'f':
  2197. X       file = optarg;
  2198. X       break;
  2199. X     case '?':
  2200. X     default:
  2201. X       exit(1);
  2202. X    }
  2203. X
  2204. X fisf = fopen(file,"r");
  2205. X if (!fisf)
  2206. X  {
  2207. X   perror("sesswho: fatal: cannot open current session file");
  2208. X   exit(2);
  2209. X  }
  2210. X if (flagreverse)
  2211. X  {
  2212. X   fseek(fisf,0,2);
  2213. X   revnum = ftell(fisf) / sizeof(sl);
  2214. X   fseek(fisf,sizeof(sl) * --revnum,0);
  2215. X  }
  2216. X
  2217. X while (fread(&sl,sizeof(sl),1,fisf) == 1)
  2218. X  {
  2219. X   if (sl.ext[0] && (sl.masterpid || flaglogouts))
  2220. X     /* XXX: requires printf with %* */
  2221. X     printf(sl.masterpid ? "%c%c  %12.12s  %-*.*s  %d\n"
  2222. X             : "%c%c  %12.12s  %-*.*s  exit\n"
  2223. X       ,sl.ext[0],sl.ext[1]
  2224. X       ,asctime(localtime(&sl.date)) + 4
  2225. X       ,SESSLOG_USERLEN
  2226. X       ,SESSLOG_USERLEN
  2227. X       ,sl.username
  2228. X       ,sl.masterpid
  2229. X      );
  2230. X   if (flagreverse)
  2231. X    {
  2232. X     if (fseek(fisf,-2 * sizeof(sl),1) == -1) /*XXX*/
  2233. X       break;
  2234. X     --revnum; /*XXX: why do we care? */
  2235. X    }
  2236. X  }
  2237. X exit(0);
  2238. X}
  2239. END_OF_FILE
  2240. if test 1539 -ne `wc -c <'sesswho.c'`; then
  2241.     echo shar: \"'sesswho.c'\" unpacked with wrong size!
  2242. fi
  2243. # end of 'sesswho.c'
  2244. fi
  2245. if test -f 'sigdfl.3' -a "${1}" != "-c" ; then 
  2246.   echo shar: Will not clobber existing file \"'sigdfl.3'\"
  2247. else
  2248. echo shar: Extracting \"'sigdfl.3'\" \(1706 characters\)
  2249. sed "s/^X//" >'sigdfl.3' <<'END_OF_FILE'
  2250. X.TH sigdfl 3
  2251. X.SH NAME
  2252. sigdfl \- invoke the default action for a signal
  2253. X.SH SYNTAX
  2254. X.B #include <sigdfl.h>
  2255. X
  2256. int \fBsigdfl(\fIsig\fB)\fR;
  2257. X
  2258. int \fBsigdfl_ttou()\fR;
  2259. X.br
  2260. int \fBsigdfl_tstp()\fR;
  2261. X.br
  2262. int \fBsigdfl_ttin()\fR;
  2263. X.br
  2264. int \fBsigdfl_stop()\fR;
  2265. X
  2266. int \fBsigdfl_abrt()\fR;
  2267. X
  2268. int \fIsig\fP;
  2269. X.SH DESCRIPTION
  2270. X.B sigdfl(\fIsig\fB)
  2271. has exactly the same effect as what happens 
  2272. if the process isn't blocking
  2273. X.I sig,
  2274. has SIG_DFL as the handler for
  2275. X.I sig,
  2276. and then receives
  2277. X.I sig.
  2278. In the case of stop signals
  2279. X(TSTP, TTIN, TTOU, STOP),
  2280. X.B sigdfl
  2281. will absorb one or more CONT
  2282. signals before returning.
  2283. X.B sigdfl
  2284. is safe against
  2285. multithreading.
  2286. X
  2287. X.B sigdfl
  2288. has several interesting uses inside signal handlers.
  2289. XFor instance, the handler for SEGV can clean up the tty
  2290. and then call
  2291. X.B sigdfl(\fRSIGSEGV\fB).
  2292. Unlike a simple
  2293. X.B abort(),
  2294. this doesn't hide the reason for the core dump from the user.
  2295. Similar comments apply to the stop signals.
  2296. Note that processes handling a stop signal should
  2297. take steps to ensure that they are back in the foreground
  2298. after
  2299. X.B sigdfl
  2300. returns.
  2301. X
  2302. X.B sigdfl
  2303. returns 0 normally, -1 with
  2304. errno
  2305. set in case of various impossible errors.
  2306. X
  2307. X.B sigdfl_tstp()
  2308. is the same as
  2309. X.B sigdfl(\fRSIGTSTP\fB).
  2310. On systems not supporting
  2311. SIGTSTP,
  2312. X.B sigdfl_tstp
  2313. returns -1 with errno ENOTTY.
  2314. Similar comments apply to
  2315. X.B sigdfl_stop(),
  2316. X.B sigdfl_ttin(),
  2317. and
  2318. X.B sigdfl_ttou().
  2319. X.B sigdfl_abrt()
  2320. is a professional version of
  2321. X.B abort();
  2322. it will dump core with the ABRT signal,
  2323. even if an ABRT handler is in place.
  2324. X
  2325. SIG_DFL
  2326. could, in principle, be implemented as
  2327. X.B sigdfl.
  2328. X.SH VERSION
  2329. sigdfl 1.0, July 18, 1991.
  2330. X.SH AUTHOR
  2331. Placed into the public domain by Daniel J. Bernstein.
  2332. X.SH "SEE ALSO"
  2333. signal(3),
  2334. abort(3)
  2335. END_OF_FILE
  2336. if test 1706 -ne `wc -c <'sigdfl.3'`; then
  2337.     echo shar: \"'sigdfl.3'\" unpacked with wrong size!
  2338. fi
  2339. # end of 'sigdfl.3'
  2340. fi
  2341. if test -f 'tplay.c' -a "${1}" != "-c" ; then 
  2342.   echo shar: Will not clobber existing file \"'tplay.c'\"
  2343. else
  2344. echo shar: Extracting \"'tplay.c'\" \(1590 characters\)
  2345. sed "s/^X//" >'tplay.c' <<'END_OF_FILE'
  2346. X/* tplay.c: play back a tape
  2347. Daniel J. Bernstein, brnstnd@nyu.edu.
  2348. Depends on sigsched.h, timer.h.
  2349. Requires read()/write(), i.e., UNIX.
  2350. X7/27/91: Baseline. tplay 1.0, public domain.
  2351. No known patent problems.
  2352. X
  2353. Documentation in tplay.1.
  2354. X
  2355. X*/
  2356. X
  2357. X#include "sigsched.h"
  2358. X#include "timer.h"
  2359. X
  2360. static char hdr[8];
  2361. static char buf[256];
  2362. static timer_clock latest;
  2363. static timer_sig tsig;
  2364. static int flageof = 0;
  2365. X
  2366. void doit(n)
  2367. int n; /* if nonzero, there's data waiting to be written */
  2368. X{
  2369. X int r;
  2370. X timer_clock now;
  2371. X timer_clock diff;
  2372. X int x;
  2373. X
  2374. X while (!flageof)
  2375. X  {
  2376. X   x = 1 + (unsigned int) (unsigned char) hdr[7];
  2377. X   if (n)
  2378. X    {
  2379. X     n = 0;
  2380. X     while (n < x)
  2381. X      {
  2382. X       r = write(1,buf + n,x - n);
  2383. X       if (r <= 0) ; /*XXX*/
  2384. X       n += r;
  2385. X      }
  2386. X    }
  2387. X   r = read(0,hdr,8); /* eighth byte is length of data */
  2388. X   if (r == -1)
  2389. X     ; /*XXX*/
  2390. X   if (r < 7)
  2391. X     ; /*XXX*/
  2392. X   if (r == 7)
  2393. X     flageof = 1;
  2394. X   else
  2395. X    {
  2396. X     x = 1 + (unsigned int) (unsigned char) hdr[7];
  2397. X     n = 0;
  2398. X     while (n < x)
  2399. X      {
  2400. X       r = read(0,buf + n,x - n);
  2401. X       if (r == -1) ; /*XXX*/
  2402. X       if (r == 0) ; /*XXX*/
  2403. X       n += r;
  2404. X      }
  2405. X    }
  2406. X   diff.usec = (hdr[2] * 256 + hdr[1]) * 256 + hdr[0];
  2407. X   diff.sec = ((hdr[6] * 256 + hdr[5]) * 256 + hdr[4]) * 256 + hdr[3];
  2408. X   if (diff.sec || diff.usec)
  2409. X    {
  2410. X     now = latest; /*XXX: structure copying */
  2411. X     timer_sum(&now,&diff,&latest);
  2412. X     timer_setsig(&tsig,TIMER_REAL,&latest);
  2413. X     ss_schedonce(&tsig.sig,doit,1);
  2414. X     break;
  2415. X    }
  2416. X  }
  2417. X}
  2418. X
  2419. main()
  2420. X{
  2421. X timer_now(TIMER_REAL,&latest);
  2422. X ss_schedonce(ss_asap(),doit,0);
  2423. X timer_init();
  2424. X ss_exec();
  2425. X exit(0);
  2426. X}
  2427. END_OF_FILE
  2428. if test 1590 -ne `wc -c <'tplay.c'`; then
  2429.     echo shar: \"'tplay.c'\" unpacked with wrong size!
  2430. fi
  2431. # end of 'tplay.c'
  2432. fi
  2433. if test -f 'trecord.1' -a "${1}" != "-c" ; then 
  2434.   echo shar: Will not clobber existing file \"'trecord.1'\"
  2435. else
  2436. echo shar: Extracting \"'trecord.1'\" \(904 characters\)
  2437. sed "s/^X//" >'trecord.1' <<'END_OF_FILE'
  2438. X.TH trecord 1
  2439. X.SH NAME
  2440. trecord \- tape-record input
  2441. X.SH SYNTAX
  2442. X.B trecord
  2443. X.SH DESCRIPTION
  2444. X.B trecord
  2445. records its input, including timing information,
  2446. and sends the resulting
  2447. X.I tape
  2448. to its output.
  2449. The tape can be played with
  2450. X.B tplay.
  2451. X
  2452. A useful idiom is
  2453. X.PP
  2454. X.EX
  2455. trecord | tee tapefile | tplay
  2456. X.EE
  2457. X.PP
  2458. which copies its input to its output,
  2459. meanwhile tape-recording the input in
  2460. X.I tapefile.
  2461. X
  2462. The (machine-independent)
  2463. X.I tape
  2464. format is any number of
  2465. X7-byte records separated by variable-length records.
  2466. XEach 7-byte record consists of three bytes giving a microsecond
  2467. delay, low byte first, and four bytes giving a second delay, low
  2468. byte first. A variable-length record of length
  2469. X.I n + 2
  2470. has first byte
  2471. X.I n
  2472. and contains actual data
  2473. in the remaining
  2474. X.I n + 1
  2475. bytes.
  2476. X.SH VERSION
  2477. trecord version 1.0, 7/27/91.
  2478. X.SH AUTHOR
  2479. Placed into the public domain by Daniel J. Bernstein.
  2480. X.SH "SEE ALSO"
  2481. tplay(1),
  2482. tee(1)
  2483. END_OF_FILE
  2484. if test 904 -ne `wc -c <'trecord.1'`; then
  2485.     echo shar: \"'trecord.1'\" unpacked with wrong size!
  2486. fi
  2487. # end of 'trecord.1'
  2488. fi
  2489. if test -f 'trecord.c' -a "${1}" != "-c" ; then 
  2490.   echo shar: Will not clobber existing file \"'trecord.c'\"
  2491. else
  2492. echo shar: Extracting \"'trecord.c'\" \(1106 characters\)
  2493. sed "s/^X//" >'trecord.c' <<'END_OF_FILE'
  2494. X/* trecord.c: tape-record the input
  2495. Daniel J. Bernstein, brnstnd@nyu.edu.
  2496. Depends on timer.h.
  2497. Requires read()/write(), i.e., UNIX.
  2498. X7/27/91: Baseline. trecord 1.0, public domain.
  2499. No known patent problems.
  2500. X
  2501. Documentation in trecord.1.
  2502. X*/
  2503. X
  2504. X#include "timer.h"
  2505. X
  2506. static char buf[8 + 256];
  2507. X
  2508. main()
  2509. X{
  2510. X timer_clock latest;
  2511. X timer_clock now;
  2512. X timer_clock diff;
  2513. X int r;
  2514. X int n;
  2515. X int w;
  2516. X
  2517. X if (timer_now(TIMER_REAL,&latest) == -1)
  2518. X   ; /*XXX*/
  2519. X do
  2520. X  {
  2521. X   r = read(0,buf + 8,sizeof(buf) - 8);
  2522. X   if (r == -1)
  2523. X     ; /*XXX*/
  2524. X   if (timer_now(TIMER_REAL,&now) == -1)
  2525. X     ; /*XXX*/
  2526. X   if (timer_diff(&now,&latest,&diff) < 0)
  2527. X     ; /* time warp! */
  2528. X   latest = now;
  2529. X   buf[0] = diff.usec & 255;
  2530. X   buf[1] = (diff.usec / 256) & 255;
  2531. X   buf[2] = (diff.usec / 65536) & 255;
  2532. X   buf[3] = diff.sec & 255;
  2533. X   buf[4] = (diff.sec / 256) & 255;
  2534. X   buf[5] = (diff.sec / 65536) & 255;
  2535. X   buf[6] = (diff.sec / 16777216) & 255;
  2536. X   buf[7] = r - 1;
  2537. X   r += 8;
  2538. X   if (r == 8)
  2539. X     r = 7;
  2540. X   n = 0;
  2541. X   while (n < r)
  2542. X    {
  2543. X     w = write(1,buf + n,r - n);
  2544. X     if (w < 0)
  2545. X       ; /*XXX*/
  2546. X     n += w;
  2547. X    }
  2548. X  }
  2549. X while (r != 7);
  2550. X exit(0);
  2551. X}
  2552. END_OF_FILE
  2553. if test 1106 -ne `wc -c <'trecord.c'`; then
  2554.     echo shar: \"'trecord.c'\" unpacked with wrong size!
  2555. fi
  2556. # end of 'trecord.c'
  2557. fi
  2558. if test -f 'tscript.1' -a "${1}" != "-c" ; then 
  2559.   echo shar: Will not clobber existing file \"'tscript.1'\"
  2560. else
  2561. echo shar: Extracting \"'tscript.1'\" \(829 characters\)
  2562. sed "s/^X//" >'tscript.1' <<'END_OF_FILE'
  2563. X.TH tscript 1
  2564. X.SH NAME
  2565. tscript \- make tape of terminal session
  2566. X.SH SYNOPSIS
  2567. X.B tscript
  2568. X[
  2569. X.B \-a
  2570. X] [
  2571. X.I file ...
  2572. X]
  2573. X.SH DESCRIPTION
  2574. X.B tscript
  2575. makes a tape of everything printed on your terminal.
  2576. The tape is written to the named
  2577. X.I file\fRs,
  2578. or appended to
  2579. X.I file
  2580. if the
  2581. X.B \-a
  2582. option is given.
  2583. If you don't give a filename,
  2584. the tape is saved in the file
  2585. X.I tapescript.
  2586. X
  2587. The difference between
  2588. X.B tscript
  2589. and
  2590. X.B script
  2591. is that
  2592. X.B tscript
  2593. records the time between characters.
  2594. While
  2595. X.B script
  2596. produces a human-readable record,
  2597. the output of
  2598. X.B tscript
  2599. must be played back with
  2600. X.B tplay.
  2601. X
  2602. X.B tscript
  2603. runs whatever shell is in environment variable
  2604. X.I SHELL, default /bin/sh.
  2605. The tape ends when the forked shell exits.
  2606. X
  2607. Note that
  2608. X.B tscript
  2609. requires both
  2610. X.B tplay
  2611. and
  2612. X.B trecord
  2613. to run.
  2614. X.SH "SEE ALSO"
  2615. script(1),
  2616. tplay(1),
  2617. trecord(1)
  2618. END_OF_FILE
  2619. if test 829 -ne `wc -c <'tscript.1'`; then
  2620.     echo shar: \"'tscript.1'\" unpacked with wrong size!
  2621. fi
  2622. # end of 'tscript.1'
  2623. fi
  2624. if test -f 'ttydetach.c' -a "${1}" != "-c" ; then 
  2625.   echo shar: Will not clobber existing file \"'ttydetach.c'\"
  2626. else
  2627. echo shar: Extracting \"'ttydetach.c'\" \(1126 characters\)
  2628. sed "s/^X//" >'ttydetach.c' <<'END_OF_FILE'
  2629. X#include <stdio.h>
  2630. X#include <sys/file.h>
  2631. X#include <sys/ioctl.h>
  2632. X#include <errno.h>
  2633. extern int errno;
  2634. X#include "env.h"
  2635. X#include "config/posix.h"
  2636. X
  2637. main(argc,argv)
  2638. int argc;
  2639. char *argv[];
  2640. X{
  2641. X int fd;
  2642. X int dummy;
  2643. X if (argc < 2)
  2644. X  {
  2645. X   fputs("Usage: ttydetach program [ arg ... ]\n",stderr);
  2646. X   exit(1);
  2647. X  }
  2648. X if (env_unset("PTY") == -1)
  2649. X  {
  2650. X   fputs("ttydetach: fatal: out of memory\n",stderr);
  2651. X   exit(2);
  2652. X  }
  2653. X fd = open("/dev/tty",O_RDWR);
  2654. X if (fd == -1)
  2655. X  {
  2656. X   if (errno == EBUSY) /* damn! */
  2657. X    {
  2658. X     if ((ioctl(0,TIOCNOTTY,0) == -1)
  2659. X       &&(ioctl(1,TIOCNOTTY,0) == -1)
  2660. X       &&(ioctl(2,TIOCNOTTY,0) == -1)
  2661. X       &&(ioctl(3,TIOCNOTTY,0) == -1)
  2662. X       )
  2663. X     fputs("ttydetach: warning: unable to detach from tty: exclusive-use set\n",stderr);
  2664. X       /* but it's not as if we didn't try... */
  2665. X    }
  2666. X  }
  2667. X else
  2668. X  {
  2669. X   if (ioctl(fd,TIOCNOTTY,0) == -1)
  2670. X     perror("ttydetach: warning: unable to detach from tty");
  2671. X   close(fd);
  2672. X  }
  2673. X if (ioctl(3,TIOCGPGRP,&dummy) == -1)
  2674. X   close(3);
  2675. X#ifdef POSIX_SILLINESS /* XXX: sigh... */
  2676. X setsid();
  2677. X#endif
  2678. X execvp(argv[1],argv + 1);
  2679. X perror("ttydetach: fatal: cannot execute");
  2680. X exit(4);
  2681. X}
  2682. END_OF_FILE
  2683. if test 1126 -ne `wc -c <'ttydetach.c'`; then
  2684.     echo shar: \"'ttydetach.c'\" unpacked with wrong size!
  2685. fi
  2686. # end of 'ttydetach.c'
  2687. fi
  2688. if test -f 'ttydfl.7' -a "${1}" != "-c" ; then 
  2689.   echo shar: Will not clobber existing file \"'ttydfl.7'\"
  2690. else
  2691. echo shar: Extracting \"'ttydfl.7'\" \(1331 characters\)
  2692. sed "s/^X//" >'ttydfl.7' <<'END_OF_FILE'
  2693. X.TH ttydfl 7
  2694. X.SH NAME
  2695. ttydfl \- tty default settings
  2696. X.SH DESCRIPTION
  2697. This manual page describes a standard set of
  2698. tty settings,
  2699. as respected by various programs including
  2700. X.B pty(1).
  2701. X
  2702. X.B ttydfl
  2703. is in the old tty discipline.
  2704. Its input and output speeds are EXTB.
  2705. X(Note that ttys connected directly to modems will typically have
  2706. lower speeds.)
  2707. X
  2708. XEven and odd parity characters are supported;
  2709. the high bit of an 8-bit character is stripped.
  2710. DEC ctrl-Q processing is enabled.
  2711. X
  2712. The erase character is delete (ASCII 127).
  2713. The kill (erase line) character is ctrl-U (21).
  2714. The interrupt character is ctrl-C (3).
  2715. The quit character is ctrl-backslash (28).
  2716. The start character is ctrl-Q (17).
  2717. The stop character is ctrl-S (19).
  2718. The end-of-file character is ctrl-D (4).
  2719. The alternate end-of-file character, if any, is undefined.
  2720. X
  2721. The suspend character is ctrl-Z (26).
  2722. The delayed suspend character is ctrl-Y (25).
  2723. X(Note that Suns do not handle delayed suspend processing.)
  2724. The reprint character is ctrl-R (18).
  2725. The flush character is ctrl-O (15).
  2726. The word-erase character is ctrl-W (23).
  2727. The literal-next character is ctrl-V (22).
  2728. X
  2729. On systems supporting auxiliary characters,
  2730. the use-status key is ctrl-T (20),
  2731. and the following status bits are set:
  2732. load1, load5, load15, rawcpu, uptime, pgrp, childs,
  2733. pcpu, state.
  2734. X.SH "SEE ALSO"
  2735. pty(1),
  2736. tty(4)
  2737. END_OF_FILE
  2738. if test 1331 -ne `wc -c <'ttydfl.7'`; then
  2739.     echo shar: \"'ttydfl.7'\" unpacked with wrong size!
  2740. fi
  2741. # end of 'ttydfl.7'
  2742. fi
  2743. if test -f 'username.c' -a "${1}" != "-c" ; then 
  2744.   echo shar: Will not clobber existing file \"'username.c'\"
  2745. else
  2746. echo shar: Extracting \"'username.c'\" \(798 characters\)
  2747. sed "s/^X//" >'username.c' <<'END_OF_FILE'
  2748. X/* username.c, username.h: username-uid conversions
  2749. Daniel J. Bernstein, brnstnd@nyu.edu.
  2750. Depends on fmt.h, scan.h.
  2751. Requires getpwuid(), getpwnam().
  2752. X7/18/91: Rewritten to use fmt/scan. username 1.1, public domain.
  2753. X5/1/91: Baseline. username 1.0, public domain.
  2754. No known patent problems.
  2755. X
  2756. XXXX: cache
  2757. X
  2758. X*/
  2759. X
  2760. X#include <pwd.h>
  2761. X#include "username.h"
  2762. X#include "fmt.h"
  2763. X#include "scan.h"
  2764. X
  2765. int uid2username(uid,unp)
  2766. int uid;
  2767. char **unp;
  2768. X{
  2769. X struct passwd *pw;
  2770. X static char un[FMT_ULONG + 1];
  2771. X
  2772. X if (pw = getpwuid(uid))
  2773. X  {
  2774. X   *unp = pw->pw_name;
  2775. X   return 0;
  2776. X  }
  2777. X un[fmt_uint(un,uid)] = 0;
  2778. X *unp = un;
  2779. X return 1;
  2780. X}
  2781. X
  2782. int username2uid(un,uid)
  2783. char *un;
  2784. int *uid;
  2785. X{
  2786. X struct passwd *pw;
  2787. X
  2788. X if (!un[scan_uint(un,uid)])
  2789. X   return 1;
  2790. X pw = getpwnam(un);
  2791. X if (!pw)
  2792. X   return -1; /*XXX*/
  2793. X *uid = pw->pw_uid;
  2794. X return 0;
  2795. X}
  2796. END_OF_FILE
  2797. if test 798 -ne `wc -c <'username.c'`; then
  2798.     echo shar: \"'username.c'\" unpacked with wrong size!
  2799. fi
  2800. # end of 'username.c'
  2801. fi
  2802. if test -f 'users.c' -a "${1}" != "-c" ; then 
  2803.   echo shar: Will not clobber existing file \"'users.c'\"
  2804. else
  2805. echo shar: Extracting \"'users.c'\" \(1370 characters\)
  2806. sed "s/^X//" >'users.c' <<'END_OF_FILE'
  2807. X/* users.c: clone of users program
  2808. Daniel J. Bernstein, brnstnd@nyu.edu.
  2809. Depends on radixsort.h, sod.h, ralloc.h.
  2810. Requires BSD: /etc/utmp, <utmp.h>.
  2811. X7/23/91: Baseline. users 2.0, public domain.
  2812. No known patent problems.
  2813. X
  2814. Documentation in users.1.
  2815. X*/
  2816. X
  2817. X#include <stdio.h>
  2818. X#include <sys/types.h>
  2819. X#include <utmp.h>
  2820. X#include "config/utmpfile.h"
  2821. X#include "radixsort.h"
  2822. X#include "sod.h"
  2823. X#include "ralloc.h"
  2824. X
  2825. struct utmp ut;
  2826. SODdecl(namestack,struct { char name[sizeof(ut.ut_name) + 1]; } );
  2827. X
  2828. main()
  2829. X{
  2830. X register FILE *fi;
  2831. X namestack namehead;
  2832. X namestack name;
  2833. X int numnames;
  2834. X char **base;
  2835. X int i;
  2836. X
  2837. X numnames = 0;
  2838. X namehead = 0;
  2839. X if (!(fi = fopen(UTMP_FILE,"r")))
  2840. X   exit(1); /*XXX*/
  2841. X while (fread((char *) &ut,sizeof(ut),1,fi))
  2842. X   if (ut.ut_name[0])
  2843. X    {
  2844. X     name = SODalloc(namestack,name,ralloc);
  2845. X     if (!name)
  2846. X       exit(1); /*XXX*/
  2847. X     strncpy(SODdata(name).name,ut.ut_name,sizeof(ut.ut_name));
  2848. X     SODpush(namehead,name);
  2849. X     ++numnames;
  2850. X    }
  2851. X fclose(fi);
  2852. X
  2853. X base = RALLOC(char *,numnames);
  2854. X if (!base)
  2855. X   exit(1); /*XXX*/
  2856. X
  2857. X i = 0;
  2858. X for (name = namehead;name;name = SODnext(name))
  2859. X   base[i++] = SODdata(name).name;
  2860. X if (radixsort7(base,numnames,0,(unsigned char *) 0,0,ralloc,rfree) == -1)
  2861. X   exit(1); /*XXX*/
  2862. X
  2863. X i = 0;
  2864. X for (;;)
  2865. X  {
  2866. X   if (i)
  2867. X     putchar(' ');
  2868. X   if (i == numnames)
  2869. X     break;
  2870. X   fputs(base[i],stdout);
  2871. X   ++i;
  2872. X  }
  2873. X putchar('\n');
  2874. X exit(0);
  2875. X}
  2876. END_OF_FILE
  2877. if test 1370 -ne `wc -c <'users.c'`; then
  2878.     echo shar: \"'users.c'\" unpacked with wrong size!
  2879. fi
  2880. # end of 'users.c'
  2881. fi
  2882. if test -f 'wall.c' -a "${1}" != "-c" ; then 
  2883.   echo shar: Will not clobber existing file \"'wall.c'\"
  2884. else
  2885. echo shar: Extracting \"'wall.c'\" \(1768 characters\)
  2886. sed "s/^X//" >'wall.c' <<'END_OF_FILE'
  2887. X/* Public domain. */
  2888. X
  2889. X#include <sys/types.h>
  2890. X#include <sys/file.h>
  2891. X#ifdef BSD
  2892. X#include <limits.h>
  2893. X#endif
  2894. X#include <stdio.h>
  2895. X#include <strings.h>
  2896. X#include <utmp.h>
  2897. X#include <pwd.h>
  2898. X#include <time.h>
  2899. X#include <ctype.h>
  2900. X#include "fmt.h"
  2901. X#include "config/utmpfile.h"
  2902. extern unsigned short getuid();
  2903. extern char *ttyname();
  2904. extern long time();
  2905. X
  2906. main()
  2907. X{ 
  2908. X register FILE *fi;
  2909. X struct utmp ut;
  2910. X char fntty[30];
  2911. X int fd;
  2912. X char buf[10000];
  2913. X char *username;
  2914. X struct passwd *pw;
  2915. X char hostname[64];
  2916. X char *ttyn;
  2917. X long t;
  2918. X struct tm *tm;
  2919. X int r;
  2920. X int pos;
  2921. X
  2922. X if (!(pw = getpwuid((int) getuid())))
  2923. X  {
  2924. X   fprintf(stderr,"write: who are you?\n");
  2925. X   exit(1);
  2926. X  }
  2927. X username = pw->pw_name;
  2928. X
  2929. X gethostname(hostname,sizeof(hostname));
  2930. X
  2931. X if (!(ttyn = ttyname(2)))
  2932. X  {
  2933. X   fprintf(stderr,"wall: Can't find your tty\n");
  2934. X   exit(1);
  2935. X  }
  2936. X
  2937. X t = time((long *) 0);
  2938. X tm = localtime(&t);
  2939. X
  2940. X sprintf(buf,"\nBroadcast message from %s@%s on %s at %d:%02d ...%c\n\n",
  2941. X        username,hostname,ttyn + 5,tm->tm_hour,tm->tm_min,7);
  2942. X pos = strlen(buf);
  2943. X  {
  2944. X   static char pre[] =
  2945. X"End your message with the EOF character. This is how it will show up:";
  2946. X   write(1,pre,strlen(pre));
  2947. X  }
  2948. X write(1,buf,pos);
  2949. X while ((pos < 10000) && ((r = read(0,buf + pos,10000 - pos)) > 0))
  2950. X   pos += r;
  2951. X if (fmt_nvis(FMT_LEN,buf,pos) != pos + 1) /* +1 for extra beep */
  2952. X  {
  2953. X   fprintf(stderr,"wall: sorry, that message has control characters\n");
  2954. X   exit(1);
  2955. X  }
  2956. X
  2957. X if (fi = fopen(UTMP_FILE,"r"))
  2958. X   while (fread((char *) &ut,sizeof(ut),1,fi))
  2959. X     if (ut.ut_name[0])
  2960. X      {
  2961. X       sprintf(fntty,"/dev/%.8s",ut.ut_line);
  2962. X       if ((fd = open(fntty,O_WRONLY)) == -1)
  2963. X         fprintf(stderr,"wall: cannot write to %.8s\n",ut.ut_line);
  2964. X       else
  2965. X        {
  2966. X     write(fd,buf,pos);
  2967. X         close(fd);
  2968. X        }
  2969. X      }
  2970. X
  2971. X exit(0);
  2972. X}
  2973. END_OF_FILE
  2974. if test 1768 -ne `wc -c <'wall.c'`; then
  2975.     echo shar: \"'wall.c'\" unpacked with wrong size!
  2976. fi
  2977. # end of 'wall.c'
  2978. fi
  2979. if test -f 'who.1' -a "${1}" != "-c" ; then 
  2980.   echo shar: Will not clobber existing file \"'who.1'\"
  2981. else
  2982. echo shar: Extracting \"'who.1'\" \(1353 characters\)
  2983. sed "s/^X//" >'who.1' <<'END_OF_FILE'
  2984. X.TH who 1
  2985. X.SH NAME
  2986. who \- show who is logged on
  2987. X.SH SYNOPSIS
  2988. X.B who
  2989. X[
  2990. X\fB\-lL\fI
  2991. X] [
  2992. X.I file
  2993. X] [
  2994. X.B "am I"
  2995. X]
  2996. X.SH DESCRIPTION
  2997. X.B who
  2998. lists the login name, terminal name, and login time
  2999. for each current user.
  3000. Normally
  3001. X.B who
  3002. uses
  3003. X.I /etc/utmp,
  3004. and omits
  3005. logged-out terminals.
  3006. If you give it a
  3007. X.I file,
  3008. such as
  3009. X/usr/adm/wtmp,
  3010. it will use that file instead,
  3011. and include logouts as lines with a blank username.
  3012. Other types of entries in
  3013. X/usr/adm/wtmp
  3014. are documented
  3015. in
  3016. utmp(5).
  3017. X.PP
  3018. Option
  3019. X.B\-L
  3020. restricts the display to lines which actually have someone logged on,
  3021. omitting any lines with a blank username, just as
  3022. X.B who
  3023. does normally with no arguments.
  3024. Option
  3025. X.B\-l
  3026. shows all lines, just as
  3027. X.B who
  3028. does normally with a
  3029. X.I file
  3030. argument.
  3031. X.PP
  3032. With two (or more) arguments,
  3033. as in
  3034. X.B who am I
  3035. X(and also 
  3036. X.B who are you),
  3037. X.B who
  3038. tells who you are logged in as,
  3039. including the local host name.
  3040. X.SH COMPATIBILITY
  3041. Standard
  3042. X.B who am i
  3043. does not give a meaningful error when its input is not a terminal;
  3044. this version does.
  3045. Standard
  3046. X.B who
  3047. does not have the
  3048. X.B\-l
  3049. option.
  3050. Different versions of
  3051. X.B who
  3052. vary in how they treat three or more arguments.
  3053. Other than that, this is an exact clone.
  3054. X.SH BUGS
  3055. None known.
  3056. X.SH VERSION
  3057. who version 2.0, 7/22/91.
  3058. X.SH AUTHOR
  3059. Placed into the public domain by Daniel J. Bernstein.
  3060. X.SH FILES
  3061. X/etc/utmp
  3062. X.SH "SEE ALSO"
  3063. getuid(2), utmp(5)
  3064. END_OF_FILE
  3065. if test 1353 -ne `wc -c <'who.1'`; then
  3066.     echo shar: \"'who.1'\" unpacked with wrong size!
  3067. fi
  3068. # end of 'who.1'
  3069. fi
  3070. if test -f 'write.1' -a "${1}" != "-c" ; then 
  3071.   echo shar: Will not clobber existing file \"'write.1'\"
  3072. else
  3073. echo shar: Extracting \"'write.1'\" \(1827 characters\)
  3074. sed "s/^X//" >'write.1' <<'END_OF_FILE'
  3075. X.TH write 1
  3076. X.SH NAME
  3077. write \- write to another user
  3078. X.SH SYNOPSIS
  3079. X.B write
  3080. X.I user
  3081. X[
  3082. X.I ttyname
  3083. X]
  3084. X.SH DESCRIPTION
  3085. X.B write
  3086. copies lines from your terminal to that of
  3087. another user.
  3088. This clone version
  3089. starts and (if you don't kill the process)
  3090. ends your message with identifying lines.
  3091. It also
  3092. precedes each line with your username.
  3093. X
  3094. If you want to write to a user who is logged in more than once,
  3095. you can
  3096. choose a particular terminal with
  3097. X.I ttyname.
  3098. X(This misfeature is deprecated.)
  3099. Otherwise
  3100. X.B write
  3101. will choose a terminal for you.
  3102. X
  3103. The other user can use
  3104. X.B mesg
  3105. to allow or deny
  3106. X.B write
  3107. permission.
  3108. In many recent versions of
  3109. X.B write,
  3110. you cannot write to a user unless you are also allowing messages.
  3111. Unfortunately, this adds absolutely no security, because you can
  3112. turn messages right back off after starting
  3113. X.B write.
  3114. This clone version exhibits the right behavior:
  3115. it checks
  3116. X.B mesg
  3117. permission on the other end
  3118. before writing each line.
  3119. X
  3120. This version of
  3121. X.B write
  3122. does not
  3123. allow shell escapes.
  3124. X
  3125. There are many popular ways of using
  3126. X.B write
  3127. X(perhaps the most common being to
  3128. use
  3129. X.B talk
  3130. instead).
  3131. Typically each user ends each series of lines
  3132. with a distinctive signal, such as
  3133. X``ga'' (go ahead),
  3134. so that the other user can type without
  3135. worrying about messed-up output.
  3136. The number of abbreviations used in
  3137. screen conversation is immense.
  3138. See
  3139. X.B talkacros(7)
  3140. for further information.
  3141. X
  3142. This clone version of
  3143. X.B write
  3144. uses the standard input,
  3145. rather than the standard error,
  3146. to determine your tty.
  3147. X
  3148. X.B write
  3149. displays control characters in a printable form.
  3150. X.SH RESTRICTIONS
  3151. Lines longer than 500 characters
  3152. will be split in two.
  3153. X
  3154. X.B write
  3155. sleeps for a second after sending each line.
  3156. This restriction means that you can't
  3157. flood someone else's screen with a large text.
  3158. X.SH "SEE ALSO"
  3159. mesg(1),
  3160. who(1),
  3161. mail(1),
  3162. talkacros(7)
  3163. END_OF_FILE
  3164. if test 1827 -ne `wc -c <'write.1'`; then
  3165.     echo shar: \"'write.1'\" unpacked with wrong size!
  3166. fi
  3167. # end of 'write.1'
  3168. fi
  3169. echo shar: End of archive 2 \(of 9\).
  3170. cp /dev/null ark2isdone
  3171. MISSING=""
  3172. for I in 1 2 3 4 5 6 7 8 9 ; do
  3173.     if test ! -f ark${I}isdone ; then
  3174.     MISSING="${MISSING} ${I}"
  3175.     fi
  3176. done
  3177. if test "${MISSING}" = "" ; then
  3178.     echo You have unpacked all 9 archives.
  3179.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3180. else
  3181.     echo You still need to unpack the following archives:
  3182.     echo "        " ${MISSING}
  3183. fi
  3184. ##  End of shell archive.
  3185. exit 0
  3186.